Spaces:
Sleeping
Sleeping
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 IT cloud Client") | |
# import model and preprocess | |
model = load_model('model_tuned.hdf5') | |
preprocess = pickle.load(open("preprocessing.pkl", "rb")) | |
st.write('fill your profile:') | |
# user input | |
age = st.slider(label='age:', min_value=0, max_value=150, value=42, step=1) | |
sex = st.radio(label='gender:', options=['Female', 'Male']) | |
reg = st.radio(label='Region?', options=['Town', 'City', 'Village']) | |
mbr = st.selectbox(label='Membership?', 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='you join us via referral?', options=['Yes', 'No']) | |
ofr = st.radio(label='Which offer that you are using rn?', options=['Credit/Debit Card Offers', | |
'Gift Vouchers/Coupons', | |
'Without Offers']) | |
med = st.radio(label='What gadget for transaction do you usually use?', options=['Smartphone', | |
'Desktop', | |
'Both']) | |
itt = st.radio(label='internet type?', options=['Wi-Fi', 'Mobile_Data', 'Fiber_Optic']) | |
day = st.number_input(label='last login?:', min_value=0, max_value=999, value=42, step=1) | |
avt = st.number_input(label='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='monthly charge:', min_value=0.00, max_value=9999999.99, value=0.00, step=0.01) | |
alp = st.number_input(label='login period in days:', min_value=0.000000, max_value=999.999999, value=0.000000, step=0.000001) | |
pts = st.number_input(label='points in wallet:', min_value=0.000000, max_value=99999.999999, value=0.000000, step=0.000001) | |
spc = st.radio(label='special discount?', options=['Yes', 'No']) | |
ofa = st.radio(label='prefer offers?', options=['Yes', 'No']) | |
com = st.radio(label='past complaint?', options=['Yes', 'No']) | |
cst = st.selectbox(label='your past complaint status?', options=['Solved', 'Solved in Follow-up', 'Unsolved', | |
'Not Applicable', 'No Information Available']) | |
fdb = st.selectbox(label='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 will absolutely stay!' | |
else: | |
prediction = 'dangers gawat, we need to save this person!' | |
st.write('Prediction result: ') | |
st.write(prediction) |