William14045 commited on
Commit
a8914ff
1 Parent(s): be89fc0
Files changed (5) hide show
  1. churn.csv +0 -0
  2. churn_model.h5 +3 -0
  3. predict.py +96 -0
  4. prep_pipeline.pkl +3 -0
  5. requirements.txt +8 -0
churn.csv ADDED
The diff for this file is too large to render. See raw diff
 
churn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c852ec4021925e200375a5330e0e74ca88dc735dde1d7048497de30e2f1b847d
3
+ size 54056
predict.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ import pandas as pd
4
+ import numpy as np
5
+ import pickle
6
+ from datetime import datetime , time
7
+
8
+ # Load All Files
9
+ with open('prep_pipeline.pkl','rb') as file1:
10
+ prep = pickle.load(file1)
11
+
12
+ ann = load_model('churn_model.h5')
13
+
14
+ tanggal_waktu_sekarang = datetime.now().time()
15
+ waktu_sekarang = datetime.now().date()
16
+
17
+
18
+ def run():
19
+ with st.form('key=Churn_prediction'):
20
+ user_id = st.text_input('user_id:', '')
21
+ age = st.number_input("age:" ,min_value=18 , max_value=100,step=1)
22
+ gender = st.radio('gender', ('F','M'))
23
+ region_category = st.radio('region_category', ('Town','City','Village'))
24
+ membership_category = st.selectbox('membership_category', ('No Membership','Basic Membership','Silver Membership','Gold Membership','Platinum Membership','Premium Membership'), index=1)
25
+ st.markdown('---')
26
+
27
+ joining_date = st.date_input('joining_date', waktu_sekarang)
28
+ joined_through_referral = st.radio('joined_through_referral',(True,False))
29
+ preferred_offer_types = st.selectbox('preferred_offer_types',('Gift Vouchers/Coupons','Credit/Debit Card Offers','Without Offers'))
30
+ medium_of_operation = st.selectbox('medium_of_operation',('Desktop','Smartphone','Both'))
31
+ internet_option = st.radio('internet_option',('Wi-Fi','Mobile_Data','Fiber_Optic'))
32
+ last_visit_time = st.time_input('last_visit_time', tanggal_waktu_sekarang)
33
+ days_since_last_login = st.number_input('days_since_last_login', min_value=0 , max_value=1000,step=1)
34
+ avg_time_spent = st.number_input('avg_time_spent' , min_value=0 , max_value=3300,step=1)
35
+ avg_transaction_value = st.number_input('avg_transaction_value', min_value=500 , max_value=100000,step=5)
36
+ avg_frequency_login_days = st.number_input('avg_frequency_login_days', min_value=0 , max_value=75,step=1)
37
+ points_in_wallet = st.number_input('points_in_wallet',min_value=0 , max_value=2100,step=5)
38
+ used_special_discount = st.radio('used_special_discount', ('Yes','No'))
39
+ offer_application_preference = st.radio('offer_application_preference',('Yes','No'))
40
+ past_complaint = st.radio('past_complaint',('Yes','No'))
41
+ complaint_status = st.selectbox('complaint_status', ('Not Applicable' , 'Unsolved','Solved','Solved in Follow-up','No Information Available'))
42
+ feedback = st.selectbox('feedback', ('Poor Product Quality','No reason specified','Too many ads','Poor Website','Poor Customer Service','Reasonable Price','User Friendly Website','Products always in Stock','Quality Customer Care'))
43
+ submitted = st.form_submit_button('Predict')
44
+
45
+ data_inf = {
46
+ 'user_id': user_id,
47
+ 'age': age,
48
+ 'gender': gender,
49
+ 'region_category': region_category,
50
+ 'membership_category': membership_category,
51
+ 'joining_date': joining_date,
52
+ 'joined_through_referral': joined_through_referral,
53
+ 'preferred_offer_types': preferred_offer_types,
54
+ 'medium_of_operation': medium_of_operation,
55
+ 'internet_option': internet_option,
56
+ 'last_visit_time': last_visit_time,
57
+ 'days_since_last_login': days_since_last_login,
58
+ 'avg_time_spent' : avg_time_spent,
59
+ 'avg_transaction_value' : avg_transaction_value,
60
+ 'avg_frequency_login_days' : avg_frequency_login_days,
61
+ 'points_in_wallet' : points_in_wallet,
62
+ 'used_special_discount' : used_special_discount,
63
+ 'offer_application_preference' : offer_application_preference,
64
+ 'past_complaint' : past_complaint,
65
+ 'complaint_status' : complaint_status,
66
+ 'feedback' : feedback
67
+ }
68
+
69
+ data_inf = pd.DataFrame([data_inf])
70
+ positive_words = ['reasonable', 'friendly', 'always', 'stock','care','price','user','products','in']
71
+ negative_words = ['poor', 'too', 'many', 'terrible','product quality','ads','service']
72
+ def classify_sentiment(text):
73
+ words = text.lower().split()
74
+ num_positive = sum(1 for word in words if word in positive_words)
75
+ num_negative = sum(1 for word in words if word in negative_words)
76
+
77
+ if num_positive > num_negative:
78
+ return 'positif'
79
+ elif num_positive < num_negative:
80
+ return 'negatif'
81
+ else:
82
+ return 'netral'
83
+ # Menerapkan fungsi klasifikasi sentimen menggunakan apply pada DataFrame
84
+ data_inf['sentimen'] = data_inf['feedback'].apply(classify_sentiment)
85
+
86
+ final_data = prep.transform(data_inf)
87
+
88
+
89
+ if submitted:
90
+ y_pred_inf = ann.predict(final_data)
91
+ y_pred_inf = np.where(y_pred_inf >= 0.5 , 'Churn' , 'Not Churn')
92
+ st.write('Price of the car : ', str(y_pred_inf))
93
+
94
+
95
+ if __name__ == '__main__':
96
+ run()
prep_pipeline.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cdd856beb751eb858e47e0512c620ba33fe7b6571bffdd450dcef21b749c1de
3
+ size 2797
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ plotly
6
+ Pillow
7
+ numpy
8
+ scikit-learn==1.2.2