ardifarizky commited on
Commit
9795401
1 Parent(s): 7a44214

initial commit

Browse files
Files changed (4) hide show
  1. app.py +10 -0
  2. eda.py +30 -0
  3. prediction.py +98 -0
  4. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import pred
4
+
5
+ page = st.sidebar.selectbox('Page Selection: ', ('Prediction', 'EDA'))
6
+
7
+ if page == 'EDA':
8
+ eda.run()
9
+ else:
10
+ pred.run()
eda.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ from PIL import Image
7
+
8
+ st.set_page_config(
9
+ page_title= 'EDA',
10
+ layout='wide',
11
+ initial_sidebar_state='expanded'
12
+ )
13
+ st.set_option('deprecation.showPyplotGlobalUse', False)
14
+
15
+ hide_streamlit_style = """
16
+ <style>
17
+ #MainMenu {visibility: hidden;}
18
+ footer {visibility: hidden;}
19
+ </style>
20
+ """
21
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
22
+
23
+
24
+ def run():
25
+
26
+ st.title('EDA')
27
+
28
+
29
+ if __name__ == '__main__':
30
+ run()
prediction.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ from tensorflow.keras.models import load_model
6
+
7
+ #Load all files
8
+
9
+ with open('final_pipeline.pkl', 'rb') as file_1:
10
+ model_pipeline = pickle.load(file_1)
11
+
12
+ model_ann = load_model("model1.h5", compile=False)
13
+
14
+ def run():
15
+
16
+ hide_streamlit_style = """
17
+ <style>
18
+ #MainMenu {visibility: hidden;}
19
+ footer {visibility: hidden;}
20
+ </style>
21
+ """
22
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
23
+
24
+
25
+ with st.form(key='Form Hotel'):
26
+ age = st.number_input('Age',0,70,step=1)
27
+ gender = st.selectbox('Gender',('M', 'F'))
28
+ region_category = st.selectbox('Hometown',('City', 'Village', 'Town'))
29
+ membership_category = st.selectbox('Membershipo Tier',('No Membership', 'Basic Membership', 'Silver Membership',
30
+ 'Premium Membership', 'Gold Membership', 'Platinum Membership'))
31
+ joining_date = st.date_input('Input date')
32
+ joined_through_referral = st.selectbox('Joined with referral?',('Yes', 'No'))
33
+ preferred_offer_types = st.selectbox('Preferred offer types',('Without Offers', 'Credit/Debit Card Offers', 'Gift Vouchers/Coupons'))
34
+ medium_of_operation = st.selectbox('Medium of operation',('Desktop', 'Smartphone', 'Both'))
35
+ internet_option = st.selectbox('Internet option',('Wi-Fi', 'Fiber_Optic', 'Mobile_Data'))
36
+ last_visit_time = st.number_input('Last visit time',0,1,step=1)
37
+ days_since_last_login = st.number_input('Days since last login',-150,0,step=1)
38
+ avg_time_spent = st.number_input('Average time spent',0,3000,step=1)
39
+ avg_transaction_value = st.number_input('Average transaction value',0,100000,step=1)
40
+ avg_frequency_login_days = st.number_input('Average frequency login day',0,90,step=1)
41
+ points_in_wallet = st.number_input('Points in wallet',0,2000,step=1)
42
+ used_special_discount = st.selectbox('Used special discount?',('Yes', 'No'))
43
+ offer_application_preference = st.selectbox('Offer app preference?',('Yes', 'No'))
44
+ past_complaint = st.selectbox('Any past complaint?',('Yes', 'No'))
45
+ complaint_status = st.selectbox('Complaint status',('No Information Available', 'Not Applicable', 'Unsolved', 'Solved',
46
+ 'Solved in Follow-up'))
47
+ feedback = st.selectbox('Feedback',('Poor Website', 'Poor Customer Service', 'Too many ads',
48
+ 'Poor Product Quality', 'No reason specified', 'Products always in Stock',
49
+ 'Reasonable Price', 'Quality Customer Care', 'User Friendly Website'))
50
+ submitted = st.form_submit_button('Predict')
51
+
52
+
53
+ data_inf = {
54
+ 'user_id' : 'ac6e97806267549f',
55
+ 'age' : age ,
56
+ 'gender' : gender ,
57
+ 'region_category' : region_category ,
58
+ 'membership_category' : membership_category ,
59
+ 'joining_date' : joining_date ,
60
+ 'joined_through_referral' : joined_through_referral ,
61
+ 'preferred_offer_types' : preferred_offer_types ,
62
+ 'medium_of_operation' : medium_of_operation ,
63
+ 'internet_option' : internet_option ,
64
+ 'last_visit_time' : last_visit_time ,
65
+ 'days_since_last_login' : days_since_last_login ,
66
+ 'avg_time_spent' : avg_time_spent ,
67
+ 'avg_transaction_value' : avg_transaction_value ,
68
+ 'avg_frequency_login_days' : avg_frequency_login_days ,
69
+ 'points_in_wallet' : points_in_wallet ,
70
+ 'used_special_discount' : used_special_discount ,
71
+ 'offer_application_preference' : offer_application_preference ,
72
+ 'past_complaint' : past_complaint ,
73
+ 'complaint_status' : complaint_status ,
74
+ 'feedback' : feedback ,
75
+ }
76
+
77
+ data_inf = pd.DataFrame([data_inf])
78
+ st.dataframe(data_inf)
79
+
80
+ data_inf['joining_date'] = pd.to_datetime(data_inf['joining_date'])
81
+ data_inf['joining_day'] = data_inf['joining_date'].dt.day
82
+ data_inf['joining_month'] = data_inf['joining_date'].dt.month
83
+ data_inf['joining_year'] = data_inf['joining_date'].dt.year
84
+
85
+ if submitted:
86
+ data_inf_transform = model_pipeline.transform(data_inf)
87
+ y_pred_inf = model_ann.predict(data_inf_transform)
88
+ y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
89
+ y_pred_inf
90
+
91
+ if y_pred_inf == 1:
92
+ st.write('likely to be churn')
93
+ else:
94
+ st.write('likely will not be churn')
95
+ #st.write(f'# (1 = Yes, 0 = No) : {str(int(data_pred_inf))}')
96
+
97
+ if __name__ == '__main__':
98
+ run()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ seaborn
5
+ matplotlib
6
+ Pillow
7
+ plotly
8
+ scikit-learn==1.2.2
9
+ tensorflow