Upload 4 files
Browse files- app.py +93 -0
- model.h5 +3 -0
- preprocess.pkl +3 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import tensorflow as tf
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
import pickle
|
6 |
+
|
7 |
+
st.title("Churn Prediction for Telecom Client")
|
8 |
+
|
9 |
+
# import model and preprocess
|
10 |
+
|
11 |
+
model = load_model('model.h5')
|
12 |
+
preprocess = pickle.load(open("preprocess.pkl", "rb"))
|
13 |
+
|
14 |
+
st.write('Please fill your information:')
|
15 |
+
|
16 |
+
# user input
|
17 |
+
|
18 |
+
age = st.slider(label='Enter your age:', min_value=0, max_value=150, value=42, step=1)
|
19 |
+
sex = st.radio(label='Enter your gender:', options=['Female', 'Male'])
|
20 |
+
reg = st.radio(label='In which region category do you stay?', options=['Town', 'City', 'Village'])
|
21 |
+
mbr = st.selectbox(label='Which membership that you are on now?', options=['Platinum Membership', 'Premium Membership',
|
22 |
+
'Gold Membership', 'Silver Membership',
|
23 |
+
'Basic Membership', 'No Membership'])
|
24 |
+
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)
|
25 |
+
ref = st.radio(label='Did you join us through referral?', options=['Yes', 'No'])
|
26 |
+
ofr = st.radio(label='Which offer that you are currently using?', options=['Credit/Debit Card Offers',
|
27 |
+
'Gift Vouchers/Coupons',
|
28 |
+
'Without Offers'])
|
29 |
+
med = st.radio(label='What medium of transaction do you usually use?', options=['Smartphone',
|
30 |
+
'Desktop',
|
31 |
+
'Both'])
|
32 |
+
itt = st.radio(label='Which internet type that you are currently using?', options=['Wi-Fi', 'Mobile_Data', 'Fiber_Optic'])
|
33 |
+
day = st.number_input(label='How long has it been since your last login?:', min_value=0, max_value=999, value=42, step=1)
|
34 |
+
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)
|
35 |
+
mch = st.number_input(label='Enter your average monthly charge:', min_value=0.00, max_value=9999999.99, value=0.00, step=0.01)
|
36 |
+
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)
|
37 |
+
pts = st.number_input(label='Enter your points in wallet:', min_value=0.000000, max_value=99999.999999, value=0.000000, step=0.000001)
|
38 |
+
spc = st.radio(label='Did you use special discount?', options=['Yes', 'No'])
|
39 |
+
ofa = st.radio(label='Do you prefer offers?', options=['Yes', 'No'])
|
40 |
+
com = st.radio(label='Do you have past complaint?', options=['Yes', 'No'])
|
41 |
+
cst = st.selectbox(label='What was your past complaint status?', options=['Solved', 'Solved in Follow-up', 'Unsolved',
|
42 |
+
'Not Applicable', 'No Information Available'])
|
43 |
+
fdb = st.selectbox(label='What was your past feedback?', options=['Too many ads', 'Poor Product Quality', 'Poor Website',
|
44 |
+
'Poor Customer Service', 'Products always in Stock',
|
45 |
+
'Reasonable Price', 'Quality Customer Care',
|
46 |
+
'User Friendly Website', 'No reason specified'])
|
47 |
+
|
48 |
+
# convert into dataframe
|
49 |
+
|
50 |
+
data = pd.DataFrame({'age': [age],
|
51 |
+
'gender': [sex],
|
52 |
+
'region_category': [reg],
|
53 |
+
'membership_category':[mbr],
|
54 |
+
'tenure': [ten],
|
55 |
+
'joined_through_referral': [ref],
|
56 |
+
'preferred_offer_types': [ofr],
|
57 |
+
'medium_of_operation': [med],
|
58 |
+
'internet_option': [itt],
|
59 |
+
'days_since_last_login': [day],
|
60 |
+
'avg_time_spent': [avt],
|
61 |
+
'avg_transaction_value': [mch],
|
62 |
+
'avg_frequency_login_days': [alp],
|
63 |
+
'points_in_wallet':[pts],
|
64 |
+
'used_special_discount': [spc],
|
65 |
+
'offer_application_preference': [ofa],
|
66 |
+
'past_complaint': [com],
|
67 |
+
'complaint_status': [cst],
|
68 |
+
'feedback': [fdb]
|
69 |
+
})
|
70 |
+
|
71 |
+
# convert gender to the real values in table
|
72 |
+
|
73 |
+
if sex == 'Female':
|
74 |
+
sex = 'F'
|
75 |
+
else:
|
76 |
+
sex = 'M'
|
77 |
+
|
78 |
+
# preprocess the input from user
|
79 |
+
|
80 |
+
data_final = preprocess.transform(data)
|
81 |
+
|
82 |
+
# prediction
|
83 |
+
|
84 |
+
if st.button('Predict'):
|
85 |
+
prediction = model.predict(data_final).tolist()[0]
|
86 |
+
|
87 |
+
if prediction == 0:
|
88 |
+
prediction = 'Congratulations, this person most likely will stay!'
|
89 |
+
else:
|
90 |
+
prediction = 'Churn alert, we need to save this person!'
|
91 |
+
|
92 |
+
st.write('Prediction result: ')
|
93 |
+
st.write(prediction)
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5badfe90705cb7f96b35258defa610ea1216d27036bb06739b6def8a261e2d2d
|
3 |
+
size 38848
|
preprocess.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a931bb04b08fb688a4523af9e170994801ae99aba0b9c0e30c7623707b56b7d6
|
3 |
+
size 7306
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit == 1.22.0
|
2 |
+
pandas == 2.0.2
|
3 |
+
scikit-learn == 1.2.2
|
4 |
+
imbalanced-learn == 0.10.1
|
5 |
+
daal4py == 2023.1.1
|
6 |
+
feature_engine == 1.6.0
|
7 |
+
tensorflow == 2.12.0
|