Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +78 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
|
7 |
+
# import preproses
|
8 |
+
preproses = pickle.load(open("preproses.pkl", "rb"))
|
9 |
+
|
10 |
+
# import model
|
11 |
+
model = load_model('model.h5')
|
12 |
+
|
13 |
+
#title
|
14 |
+
st.title("Customer Churn Predictions")
|
15 |
+
st.write("Created by Sihar Pangaribuan")
|
16 |
+
|
17 |
+
# User imput
|
18 |
+
user_id = st.text_input('Input ID of a customer', value='')
|
19 |
+
age = st.number_input(label='Age of a customer', min_value=10, max_value=64, value=10, step=1)
|
20 |
+
gender = st.selectbox(label='Gender of a customer', options=['F','M'])
|
21 |
+
region_category = st.selectbox(label='Select Region that a customer belongs to', options=['City', 'Village', 'Town'])
|
22 |
+
membership_category = st.selectbox(label='Select Category of the membership that a customer is using', options=['No Membership', 'Basic Membership', 'Silver Membership', 'Premium Membership', 'Gold Membership', 'Platinum Membership'])
|
23 |
+
joining_date = st.text_input('Date when a customer became a member', value='')
|
24 |
+
joined_through_referral = st.selectbox(label='Whether a customer joined using any referral code or ID ?', options=['Yes','No'])
|
25 |
+
preferred_offer_types = st.selectbox(label='Select Type of offer that a customer prefers', options=['Without Offers', 'Credit/Debit Card Offers', 'Gift Vouchers/Coupons'])
|
26 |
+
medium_of_operation = st.selectbox(label='Select Medium of operation that a customer uses for transactions', options=['Desktop', 'Smartphone', 'Both'])
|
27 |
+
internet_option = st.selectbox(label='Select Type of internet service a customer uses', options=['Wi-Fi', 'Fiber_Optic', 'Mobile_Data'])
|
28 |
+
last_visit_time = st.text_input('Input The last time a customer visited the website', value='')
|
29 |
+
days_since_last_login = st.number_input(label='Imput Number of days since a customer last logged into the website', min_value=-999, max_value=26, value=-999, step=1)
|
30 |
+
avg_time_spent = st.number_input(label='Imput Average time spent by a customer on the website', min_value=0.0, max_value=3235.6, value=0.0, step=0.1)
|
31 |
+
avg_transaction_value = st.number_input(label='Imput Average transaction value of a customer', min_value=800.46, max_value=99914.05, value=800.46, step=0.1)
|
32 |
+
avg_frequency_login_days = st.number_input(label='Imput Number of times a customer has logged in to the website', min_value=0.0, max_value=73.07, value=0.0, step=0.1)
|
33 |
+
points_in_wallet = st.number_input(label='Imput Points awarded to a customer on each transaction', min_value=0.0, max_value=2069.06, value=0.0, step=0.1)
|
34 |
+
used_special_discount = st.selectbox(label='Whether a customer uses special discounts offered?', options=['Yes','No'])
|
35 |
+
offer_application_preference = st.selectbox(label='Whether a customer prefers offers?', options=['Yes','No'])
|
36 |
+
past_complaint = st.selectbox(label='Whether a customer has raised any complaints?', options=['Yes','No'])
|
37 |
+
complaint_status = st.selectbox(label='Select the complaint status', options=['No Information Available', 'Not Applicable', 'Unsolved', 'Solved', 'Solved in Follow-up'])
|
38 |
+
feedback = st.selectbox(label='Select the feedback', options=['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'])
|
39 |
+
|
40 |
+
# Convert ke data frame
|
41 |
+
data = pd.DataFrame({
|
42 |
+
'user_id':[user_id],
|
43 |
+
'age':[age],
|
44 |
+
'gender':[gender],
|
45 |
+
'region_category':[region_category],
|
46 |
+
'membership_category':[membership_category],
|
47 |
+
'joining_date':[joining_date],
|
48 |
+
'joined_through_referral':[joined_through_referral],
|
49 |
+
'preferred_offer_types':[preferred_offer_types],
|
50 |
+
'medium_of_operation':[medium_of_operation],
|
51 |
+
'internet_option':[internet_option],
|
52 |
+
'last_visit_time':[last_visit_time],
|
53 |
+
'days_since_last_login':[days_since_last_login],
|
54 |
+
'avg_time_spent':[avg_time_spent],
|
55 |
+
'avg_transaction_value':[avg_transaction_value],
|
56 |
+
'avg_frequency_login_days':[avg_frequency_login_days],
|
57 |
+
'points_in_wallet':[points_in_wallet],
|
58 |
+
'used_special_discount':[used_special_discount],
|
59 |
+
'offer_application_preference':[offer_application_preference],
|
60 |
+
'past_complaint':[past_complaint],
|
61 |
+
'complaint_status':[complaint_status],
|
62 |
+
'feedback':[feedback]
|
63 |
+
})
|
64 |
+
|
65 |
+
# Transfom data
|
66 |
+
data = preproses.transform(data)
|
67 |
+
|
68 |
+
# model predict
|
69 |
+
if st.button('Predict'):
|
70 |
+
prediction = model.predict(data).tolist()[0]
|
71 |
+
|
72 |
+
if prediction == 1:
|
73 |
+
prediction = 'Froud'
|
74 |
+
else:
|
75 |
+
prediction = 'Not Froud'
|
76 |
+
|
77 |
+
st.write('The Prediction is: ')
|
78 |
+
st.write(prediction)
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
scikit-learn
|
5 |
+
imbalanced-learn
|
6 |
+
daal4py
|
7 |
+
feature_engine
|
8 |
+
tensorflow-cpu
|