mukhlishr commited on
Commit
4639767
1 Parent(s): 937cf66

replica milestone 1

Browse files
Files changed (7) hide show
  1. 2.jpg +0 -0
  2. app.py +11 -0
  3. churn_model.h5 +3 -0
  4. eda.py +109 -0
  5. final_pipeline.pkl +3 -0
  6. prediction.py +95 -0
  7. requirements.txt +10 -0
2.jpg ADDED
app.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ navigation = st.sidebar.selectbox('page : ', ('EDA', 'Churn Prediction'))
6
+
7
+ if navigation == 'EDA':
8
+ eda.run()
9
+
10
+ else:
11
+ prediction.run()
churn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:253015b1eebae93237b0bc62a9ef768eafcc48a3b79598b264c830c65a799643
3
+ size 130772
eda.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ st.set_page_config(
10
+ page_title = 'Churn Condition',
11
+ layout = 'wide',
12
+ initial_sidebar_state='expanded'
13
+ )
14
+
15
+ def run():
16
+
17
+ # title
18
+ st.title( 'Churn Prediction')
19
+
20
+ # sub header
21
+ st.subheader('Churn or Not Churn')
22
+
23
+ # insert image
24
+ image = Image.open('2.jpg')
25
+ st.image(image, caption='image from project pro, education purpose only')
26
+
27
+ # Deskripsi
28
+ st.write('Exploratory Data from Churn dataset')
29
+
30
+ # show data frame
31
+ st.write('The first 10 Data')
32
+ df = pd.read_csv('https://raw.githubusercontent.com/mukhlishr/rasyidi/main/churn.csv')
33
+ st.dataframe(df.head(10))
34
+
35
+ # Barplot target columns
36
+ st.write('###### Churn condition ')
37
+ st.write('###### Churn = 1 ; Not Churn = 0 ')
38
+ fig=plt.figure(figsize=(15,5))
39
+ sns.countplot(x='churn_risk_score', data = df)
40
+ st.pyplot(fig)
41
+
42
+ # Barplot avg transaction value
43
+ # st.write('###### Avg Transaction Value by Customer churn')
44
+ # a=df[df['churn_risk_score']==1]['avg_transaction_value']
45
+ # fig=plt.figure(figsize=(15,5))
46
+ # sns.barplot(x=a.index, y=a)
47
+ # st.pyplot(fig)
48
+
49
+ # Barplot frequency login
50
+ st.write('###### Avg Frequency login (1 = 1-10, 2 = 11-20, ... 7 >= 51)')
51
+ bins = [-1, 10,20,30,40,50,100]
52
+ labels =[1,2,3,4,5,6,7]
53
+ df['binned_frequency_login'] = pd.cut(df['avg_frequency_login_days'], bins,labels=labels).astype(float)
54
+ fig=plt.figure(figsize=(15,5))
55
+ sns.countplot(x='binned_frequency_login', data = df)
56
+ st.pyplot(fig)
57
+
58
+ # Pieplot membership
59
+ st.write('###### Membership')
60
+ data = df['membership_category'].value_counts()
61
+ keys = df['membership_category'].value_counts().index
62
+ palette_color = sns.color_palette('bright')
63
+ fig=plt.figure(figsize=(15,5))
64
+ plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
65
+ plt.title('Pieplot')
66
+ st.pyplot(fig)
67
+
68
+ # Pieplot joined through referral
69
+ st.write('###### joined through referral')
70
+ data = df['joined_through_referral'].value_counts()
71
+ keys = df['joined_through_referral'].value_counts().index
72
+ palette_color = sns.color_palette('bright')
73
+ fig=plt.figure(figsize=(15,5))
74
+ plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
75
+ plt.title('Pieplot')
76
+ st.pyplot(fig)
77
+
78
+ # Pieplot preferred_offer_types
79
+ st.write('###### preferred offer types')
80
+ data = df['preferred_offer_types'].value_counts()
81
+ keys = df['preferred_offer_types'].value_counts().index
82
+ palette_color = sns.color_palette('bright')
83
+ fig=plt.figure(figsize=(15,5))
84
+ plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
85
+ plt.title('Pieplot')
86
+ st.pyplot(fig)
87
+
88
+ # Pieplot past_complaint
89
+ st.write('###### past complaint')
90
+ data = df['past_complaint'].value_counts()
91
+ keys = df['past_complaint'].value_counts().index
92
+ palette_color = sns.color_palette('bright')
93
+ fig=plt.figure(figsize=(15,5))
94
+ plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
95
+ plt.title('Pieplot')
96
+ st.pyplot(fig)
97
+
98
+ # Pieplot feedback
99
+ st.write('###### feedback ')
100
+ data = df['feedback'].value_counts()
101
+ keys = df['feedback'].value_counts().index
102
+ palette_color = sns.color_palette('bright')
103
+ fig=plt.figure(figsize=(15,5))
104
+ plt.pie(data, labels=keys, colors=palette_color, autopct='%.0f%%')
105
+ plt.title('Pieplot')
106
+ st.pyplot(fig)
107
+
108
+ if __name__ == '__main__':
109
+ run()
final_pipeline.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ff04c06f1136714341749382df40e154ee717071d1c89e92bbc2f4f81e8b481
3
+ size 2950
prediction.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import tensorflow
5
+ from tensorflow.keras.models import load_model
6
+ import datetime
7
+ import pickle
8
+
9
+
10
+
11
+
12
+ # Load All Files
13
+
14
+ with open('final_pipeline.pkl', 'rb') as file_1:
15
+ model_pipeline = pickle.load(file_1)
16
+
17
+ model_ann = load_model('churn_model.h5')
18
+
19
+
20
+
21
+ # bikin fungsi
22
+ def run():
23
+
24
+ with st.form(key='churn_data'):
25
+
26
+ user_id = st.text_input('User ID', value='')
27
+ age = st.number_input('Age', min_value=10, max_value=70, value=25, help='Customer Age')
28
+ gender = st.selectbox('Gender', ('F','M'), index=1, help='M = Male F= Female')
29
+ region_category = st.selectbox('Region category', ('Town','Village','City'), index=1)
30
+ membership_category = st.selectbox('Membership', ('No Membership','Basic Membership','Silver Membership', 'Gold Membership','Platinum Membership','Premium Membership'), index=1)
31
+ joining_date = st.date_input('Joining date',datetime.date(2019, 7, 6))
32
+ joined_through_referral = st.selectbox('Join using referral', ('Yes','No'), index=1)
33
+ preferred_offer_types = st.selectbox('preferred offer', ('Gift Vouchers/Coupons','Without Offers','Credit/Debit Card Offers'), index=1)
34
+ medium_of_operation = st.selectbox('device ', ('Desktop','Smartphone','Both'), index=1)
35
+ internet_option= st.selectbox('Internet', ('Mobile_data','Fiber_Optic','Wi-Fi'), index=1)
36
+ days_since_last_login = st.number_input('How many days since last login', min_value=0, max_value=30, value=5)
37
+ avg_time_spent = st.number_input('Avg time login', min_value=0, max_value=3000, value=5)
38
+ avg_transaction_value = st.number_input('Avg transaction value', min_value=0, max_value=100000, value=1000)
39
+ avg_frequency_login_days= st.number_input('Avg freq login', min_value=0, max_value=100, value=5)
40
+ points_in_wallet= st.number_input('Avg time login', min_value=0, max_value=3000, value=5)
41
+ used_special_discount = st.selectbox('Spesial discount', ('Yes','No'), index=1)
42
+ offer_application_preference = st.selectbox('app preference', ('Yes','No'), index=1)
43
+ past_complaint = st.selectbox('past complaint', ('Yes','No'), index=1)
44
+ complaint_status = st.selectbox('Complain status', ('No Information Available','Not Applicable','Solved','Solved in Follow-up','Unsolved'), index=1)
45
+ feedback = st.selectbox('Complain status', ('User Friendly Website','Too many ads','Reasonable Price','Quality Customer Care','Products always in Stock','Poor Website','Poor Product Quality','Poor Customer Service'), index=1)
46
+ st.markdown('---')
47
+
48
+ submitted = st.form_submit_button('Predict')
49
+
50
+ data_inf = {
51
+ 'user_id':user_id,
52
+ 'age': age,
53
+ 'gender':gender,
54
+ 'region_category': region_category,
55
+ 'membership_category': membership_category,
56
+ 'joining_date': joining_date,
57
+ 'joined_through_referral':joined_through_referral,
58
+ 'preferred_offer_types': preferred_offer_types,
59
+ 'medium_of_operation': medium_of_operation,
60
+ 'internet_option': internet_option,
61
+ 'days_since_last_login': days_since_last_login,
62
+ 'avg_time_spent': avg_time_spent,
63
+ 'avg_transaction_value': avg_transaction_value,
64
+ 'avg_frequency_login_days': avg_frequency_login_days,
65
+ 'points_in_wallet': points_in_wallet,
66
+ 'used_special_discount': used_special_discount,
67
+ 'offer_application_preference': offer_application_preference,
68
+ 'past_complaint': past_complaint,
69
+ 'complaint_status': complaint_status,
70
+ 'feedback': feedback
71
+ }
72
+
73
+ data_inf = pd.DataFrame([data_inf])
74
+ # Create Binning frequency login
75
+ bins = [-1, 10, 20, 30, 40, 50, 100]
76
+ labels =[1,2,3,4,6,7]
77
+ data_inf['binned_frequency_login'] = pd.cut(data_inf['avg_frequency_login_days'], bins,labels=labels).astype(float)
78
+ st.dataframe(data_inf)
79
+
80
+ if submitted:
81
+
82
+ # transform data inference
83
+ data_inf_transform = model_pipeline.transform(data_inf)
84
+
85
+ # Predict using model ann
86
+ y_pred_inf = model_ann.predict(data_inf_transform)
87
+ y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
88
+ if y_pred_inf.any() == 1:
89
+ st.write('## The Customer probably will CHURN')
90
+ else:
91
+ st.write('## The Customer probably will NOT Churn')
92
+
93
+
94
+ if __name__ == '__main__':
95
+ run()
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # daftar library yang dibutuhkan semua
2
+ streamlit
3
+ tensorflow
4
+ pandas
5
+ seaborn
6
+ matplotlib
7
+ numpy
8
+ scikit-learn==1.2.1
9
+ plotly
10
+ datetime