File size: 4,919 Bytes
83e7696 266c06a 5ffa5ea 83e7696 5598253 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
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")
# import model and preprocess
model = load_model('model.h5')
preprocess = pickle.load(open("preprocess.pkl", "rb"))
st.write('Please fill your information:')
# user input
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'])
# convert into dataframe
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]
})
# convert gender to the real values in table
if sex == 'Female':
sex = 'F'
else:
sex = 'M'
# preprocess the input from user
data_final = preprocess.transform(data)
# prediction
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) |