# Import library import streamlit as st import pandas as pd import numpy as np import pickle from tensorflow.keras.models import load_model # Load All Files # Model KNN # Load All Files # Preprocessor with open('preprocessor.pkl', 'rb') as file_1: preprocessor = pickle.load(file_1) model = load_model('best_model.h5') st.subheader('Customer Churn Prediction') st.write('Please Fill The Information Below') # make 2 columns col1, col2 = st.columns(2) col11, col22, col33 = st.columns(3) # Variabel for input data membership = ['Premium Membership', 'Platinum Membership', 'Gold Membership','Silver Membership', 'Basic Membership', 'No Membership'] with col1: membership_category = st.radio('Membership',(membership)) feedback_cat = ['Products always in Stock','Reasonable Price','User Friendly Website', 'Quality Customer Care', 'Poor Product Quality', 'Poor Website', 'Poor Customer Service', 'Too many ads', 'No reason specified'] with col2: feedback = st.radio('Feedback',(feedback_cat)) with col1: offer_application_preference = st.radio('Prefer Offer',('Yes', 'No')) with col2: preferred_offer_types = st.radio('Offer Type',('Gift Vouchers/Coupons', 'Credit/Debit Card Offers','Without Offers')) with col1: joined_through_referral = st.radio('Using Refferall',('Yes', 'No')) with col11: points_in_wallet = st.number_input('Points In Wallet',0.00, 1500.00) with col22: avg_time_spent = st.number_input('Time Spent On Website (Hours)',0.00, 3050.00) with col33: avg_transaction_value = st.number_input('Total Transcation Amount (USD)',0.00, 99900.00) with col11: avg_frequency_login_days = st.slider('Login Website In A Day',0, 70) with col22: days_since_last_login = st.slider('Days Since Last Login',0, 30) with col33: days_since_join = st.slider('Days Since Join',0, 30) # make buttom for prediction if st.button('Predict'): data_inf = pd.DataFrame({'membership_category': membership_category, 'feedback': feedback, 'points_in_wallet': points_in_wallet,'avg_transaction_value': avg_transaction_value, 'avg_frequency_login_days' : avg_frequency_login_days,'joined_through_referral' : joined_through_referral, 'offer_application_preference' : offer_application_preference, 'preferred_offer_types' : preferred_offer_types, 'avg_time_spent' : avg_time_spent, 'days_since_join' : days_since_join, 'days_since_last_login' : days_since_last_login}, index=[0]) # Preprocess data inf data_inf_trans = preprocessor.transform(data_inf) # prediction using model y_pred = model.predict(data_inf_trans, verbose=0) # Round the prediction y_pred = np.round(y_pred) if y_pred == 1: y_pred = 'Churn' else: y_pred = 'Not Churn' # make prediction into dataframe st.subheader('The Customer Will be') st.subheader(y_pred)