Spaces:
Sleeping
Sleeping
File size: 5,376 Bytes
e7e98f2 |
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import datetime
from tensorflow.keras.models import load_model
# load files
with open('full_pipeline.pkl', 'rb') as file_1:
full_pipeline = pickle.load(file_1)
model_ann = load_model('best_model.h5')
def run():
with st.form(key='from_churn'):
st.title('Prediction Page')
st.subheader('We Calculate your metric to check Customer Churn Score')
st.write('*`Please fill columns below to predict`*')
# buat variabel
age = st.number_input('Age', min_value=0,
max_value=99, value=40, step=1)
st.write('F = Female | M = Male')
gender_pick = st.radio('Gender', ('M', 'F'), index=1)
region = st.selectbox('Region', ('City', 'Village', 'Town'))
member = st.selectbox('Membership', ('No Membership', 'Basic Membership', 'Silver Membership',
'Premium Membership', 'Gold Membership', 'Platinum Membership'))
joined = st.date_input('Date when a customer became member',
datetime.date(2023, 12, 31))
join_ref = st.radio(
'Are Customer Joined Using Referral?', ('Yes', 'No'), index=1)
pref_offer = st.selectbox('Type of offer to customer', ('Without Offers', 'Credit/Debit Card Offers',
'Gift Vouchers/Coupons'))
medium = st.selectbox(
'Type of Device', ('Smartphone', 'Desktop', 'Both'))
internet_opt = st.selectbox(
'Type of internet service', ('Wi-Fi', 'Fiber_Optic', 'Mobile_Data'))
last_visit = st.time_input('The last time a customer visited the website',
datetime.time(15, 00), step=300)
last_login = st.number_input('Number of days since a customer last logged into the website',
min_value=0, max_value=366, value=4, step=1)
time_spent = st.number_input('Average time (minutes) customer spent in the platform',
min_value=0, max_value=5000, value=30, step=1)
trx_value = st.number_input('Average transaction value of a customer', min_value=0,
max_value=10_000, value=500, step=5)
login_days = st.number_input('Number of times a customer has logged in to the website', min_value=0,
max_value=10_000, value=25, step=1)
point_wallet = st.number_input('Points awarded to a customer on each transaction', min_value=0,
max_value=50_000, value=1000, step=10)
used_discount = st.radio(
'Whether a customer uses special discounts offered', ('Yes', 'No'), index=1)
pref = st.radio('Whether a customer prefers offers',
('Yes', 'No'), index=1)
past_comp = st.radio(
'Whether a customer has raised any complaints', ('Yes', 'No'), index=1)
comp_status = st.selectbox('Whether the complaints raised by a customer was resolved', ('No Information Available', 'Not Applicable', 'Unsolved',
'Solved', 'Solved in Follow-up'))
feedback = st.selectbox('Feedback provided by a customer', ('Poor Website',
'Poor Customer Service', 'Too many ads',
'Poor Product Quality', 'No reason specified',
'Products always in Stock', 'Reasonable Price',
'Quality Customer Care', 'User Friendly Website'))
st.markdown('---')
submitted = st.form_submit_button('Predict')
data_inf = {
'age': age,
'gender': gender_pick,
'region_category': region,
'membership_category': member,
'joined_through_referral': join_ref,
'preferred_offer_types': pref_offer,
'medium_of_operation': medium,
'internet_option': internet_opt,
'days_since_last_login': last_login,
'avg_time_spent': time_spent,
'avg_transaction_value': trx_value,
'avg_frequency_login_days': login_days,
'points_in_wallet': point_wallet,
'used_special_discount': used_discount,
'offer_application_preference': pref,
'past_complaint': past_comp,
'complaint_status': comp_status,
'feedback': feedback
}
data_inf = pd.DataFrame([data_inf])
# st.dataframe(data_inf.T, width=800, height=495)
if submitted:
# predict using full_pipeline
data_pipeline = full_pipeline.transform(data_inf)
y_pred_inf = model_ann.predict(data_pipeline)
y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
y_pred_inf
if y_pred_inf == 0:
st.write('Not Churn')
else:
st.write('Churn')
st.markdown('---')
if __name__ == '__main__':
run()
|