Muhamadinsani17 commited on
Commit
2f537bc
·
verified ·
1 Parent(s): c4462b5

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +84 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+
5
+
6
+ # Tampilan judul halaman
7
+ st.markdown("========================================================================================")
8
+ st.markdown("<h1 style='text-align: center;'>Welcome to the Churn Prediction Model</h1>", unsafe_allow_html=True)
9
+ st.markdown("<br>", unsafe_allow_html=True)
10
+ st.markdown("========================================================================================")
11
+
12
+ st.caption('Please enter the customer feature data input on the left side of your screen to get started!')
13
+
14
+ with st.expander('Input Feature Explanation '):
15
+ st.caption('''
16
+ |Feature|Explanation|
17
+ |---|---|
18
+ |Tenure | Tenure of customer in organization|
19
+ |Complain | Any complaint has been raised in last month|
20
+ |Day Since Last Order | Day Since last order by customer|
21
+ |Cashback Amount | Average cashback in last month|
22
+ |Number Of Device Registered | Total number of deceives is registered on particular customer|
23
+ |Satisfaction Score | Satisfactory score of customer on service|
24
+ |Prefered Order Cat | Preferred order category of customer in last month|
25
+ |Marital Status | Marital status of customer|
26
+ ''')
27
+
28
+ st.sidebar.markdown("===================================")
29
+ st.sidebar.markdown("<h1 style='text-align: center;'>Input Data Customer</h1>", unsafe_allow_html=True)
30
+ st.sidebar.markdown("<br>", unsafe_allow_html=True)
31
+ st.sidebar.markdown("===================================")
32
+ def user_input():
33
+
34
+ tenure = st.sidebar.slider('Tenure', min_value=0, max_value=100, value=50)
35
+ complain = st.sidebar.selectbox('Complain', [0, 1])
36
+ day_since_last_order = st.sidebar.slider('Days Since Last Order', min_value=0, max_value=365, value=30)
37
+ cashback_amount = st.sidebar.slider('Cashback Amount', min_value=0, max_value=1000, value=500)
38
+ number_of_device_registered = st.sidebar.slider('Number of Devices Registered', min_value=0, max_value=10, value=5)
39
+ satisfaction_score = st.sidebar.slider('Satisfaction Score', min_value=1, max_value=5, value=3)
40
+ prefered_order_cat = st.sidebar.selectbox('Preferred Order Category', ['Laptop & Accessory', 'Mobile', 'Mobile Phone',
41
+ 'Others','Fashion', 'Grocery'])
42
+ marital_status = st.sidebar.selectbox('Marital Status', ['Single', 'Married', 'Divorced'])
43
+
44
+ data = {
45
+ 'tenure': tenure,
46
+ 'complain' : complain,
47
+ 'day_since_last_order': day_since_last_order,
48
+ 'cashback_amount': cashback_amount,
49
+ 'number_of_device_registered': number_of_device_registered,
50
+ 'satisfaction_score': satisfaction_score,
51
+ 'prefered_order_cat': prefered_order_cat,
52
+ 'marital_status': marital_status,
53
+ }
54
+
55
+ features = pd.DataFrame(data, index=[0])
56
+ return features
57
+
58
+ # Menjalankan fungsi input pengguna
59
+ input = user_input()
60
+
61
+ # Menampilkan hasil input pengguna dalam bentuk tabel
62
+ st.markdown("<h2 style='text-align: left;'>User Input Result</h2>", unsafe_allow_html=True)
63
+ st.table(input)
64
+
65
+ # Memuat model yang telah disimpan sebelumnya
66
+ load_model = joblib.load("model_xgb.pkl")
67
+
68
+ # Tombol untuk memprediksi
69
+ if st.button("Predict", help='Click me!'):
70
+ # Melakukan prediksi menggunakan model
71
+ prediction = load_model.predict(input)
72
+
73
+ # Menampilkan hasil prediksi
74
+ if prediction == 1:
75
+ prediction = 'The customer is likely to churn'
76
+ else:
77
+ prediction = 'The customer is likely to stay'
78
+
79
+ st.markdown("<h4 style='text-align: center;'>Based on the information provided by the user, the model predicts:</h4>", unsafe_allow_html=True)
80
+ st.markdown(f"<h1 style='text-align: center;'>{prediction}</h1>", unsafe_allow_html=True)
81
+
82
+ # Menampilkan hasil tambahan jika input termasuk dalam salah satu jenis fraud
83
+ if prediction != "The customer is likely to stay":
84
+ st.warning('This customer falls into the churn category. Please take appropriate action to retain the customer')
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas
2
+ joblib
3
+ scikit-learn