|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import tensorflow as tf |
|
from tensorflow.keras.models import load_model |
|
import pickle |
|
|
|
st.title("Churn Prediction for Telecom Client") |
|
|
|
|
|
|
|
model = load_model('model.h5') |
|
preprocess = pickle.load(open("preprocess.pkl", "rb")) |
|
|
|
st.write('Please fill your information:') |
|
|
|
|
|
|
|
age = st.slider(label='Enter your age:', min_value=0, max_value=150, value=42, step=1) |
|
sex = st.radio(label='Enter your gender:', options=['Female', 'Male']) |
|
reg = st.radio(label='In which region category do you stay?', options=['Town', 'City', 'Village']) |
|
mbr = st.selectbox(label='Which membership that you are on now?', options=['Platinum Membership', 'Premium Membership', |
|
'Gold Membership', 'Silver Membership', |
|
'Basic Membership', 'No Membership']) |
|
ten = st.number_input(label='How long you have been using our services (in months)?:', min_value=0, max_value=999, value=42, step=1) |
|
ref = st.radio(label='Did you join us through referral?', options=['Yes', 'No']) |
|
ofr = st.radio(label='Which offer that you are currently using?', options=['Credit/Debit Card Offers', |
|
'Gift Vouchers/Coupons', |
|
'Without Offers']) |
|
med = st.radio(label='What medium of transaction do you usually use?', options=['Smartphone', |
|
'Desktop', |
|
'Both']) |
|
itt = st.radio(label='Which internet type that you are currently using?', options=['Wi-Fi', 'Mobile_Data', 'Fiber_Optic']) |
|
day = st.number_input(label='How long has it been since your last login?:', min_value=0, max_value=999, value=42, step=1) |
|
avt = st.number_input(label='How long do you usually spend on the website (in minutes)?:', min_value=0.00, max_value=9999.99, value=0.00, step=0.01) |
|
mch = st.number_input(label='Enter your average monthly charge:', min_value=0.00, max_value=9999999.99, value=0.00, step=0.01) |
|
alp = st.number_input(label='Enter your average login period in days:', min_value=0.000000, max_value=999.999999, value=0.000000, step=0.000001) |
|
pts = st.number_input(label='Enter your points in wallet:', min_value=0.000000, max_value=99999.999999, value=0.000000, step=0.000001) |
|
spc = st.radio(label='Did you use special discount?', options=['Yes', 'No']) |
|
ofa = st.radio(label='Do you prefer offers?', options=['Yes', 'No']) |
|
com = st.radio(label='Do you have past complaint?', options=['Yes', 'No']) |
|
cst = st.selectbox(label='What was your past complaint status?', options=['Solved', 'Solved in Follow-up', 'Unsolved', |
|
'Not Applicable', 'No Information Available']) |
|
fdb = st.selectbox(label='What was your past feedback?', options=['Too many ads', 'Poor Product Quality', 'Poor Website', |
|
'Poor Customer Service', 'Products always in Stock', |
|
'Reasonable Price', 'Quality Customer Care', |
|
'User Friendly Website', 'No reason specified']) |
|
|
|
|
|
|
|
data = pd.DataFrame({'age': [age], |
|
'gender': [sex], |
|
'region_category': [reg], |
|
'membership_category':[mbr], |
|
'tenure': [ten], |
|
'joined_through_referral': [ref], |
|
'preferred_offer_types': [ofr], |
|
'medium_of_operation': [med], |
|
'internet_option': [itt], |
|
'days_since_last_login': [day], |
|
'avg_time_spent': [avt], |
|
'avg_transaction_value': [mch], |
|
'avg_frequency_login_days': [alp], |
|
'points_in_wallet':[pts], |
|
'used_special_discount': [spc], |
|
'offer_application_preference': [ofa], |
|
'past_complaint': [com], |
|
'complaint_status': [cst], |
|
'feedback': [fdb] |
|
}) |
|
|
|
|
|
|
|
if sex == 'Female': |
|
sex = 'F' |
|
else: |
|
sex = 'M' |
|
|
|
|
|
|
|
data_final = preprocess.transform(data) |
|
|
|
|
|
|
|
if st.button('Predict'): |
|
prediction = model.predict(data_final) |
|
prediction = np.where(prediction >= 0.5, 1, 0) |
|
|
|
if prediction == 0: |
|
prediction = 'Congratulations, this person most likely will stay!' |
|
else: |
|
prediction = 'Churn alert, we need to save this person!' |
|
|
|
st.write('Prediction result: ') |
|
st.write(prediction) |