Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- EDA.py +70 -0
- app.py +10 -0
- churn_model.h5 +3 -0
- final_pipeline.pkl +3 -0
- prediction.py +94 -0
- requirements.txt +9 -0
EDA.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = 'Customer Churn - EDA',
|
10 |
+
layout = 'wide',
|
11 |
+
initial_sidebar_state = 'expanded'
|
12 |
+
)
|
13 |
+
|
14 |
+
def run():
|
15 |
+
|
16 |
+
# Membuat Judul
|
17 |
+
st.title('Customer Churn Prediction')
|
18 |
+
|
19 |
+
# Membaut subheader
|
20 |
+
st.subheader('EDA for analysis customer churn')
|
21 |
+
|
22 |
+
# Membuat garis lurus
|
23 |
+
st.markdown('---')
|
24 |
+
|
25 |
+
# Menambahkan deskripsi
|
26 |
+
st.write('**Why Churn Important?**')
|
27 |
+
|
28 |
+
st.write('Churn, or customer churn, refers to the phenomenon where customers discontinue their relationship with a company or brand. It is a critical metric for businesses, particularly in subscription-based or recurring revenue models. Churn can have a significant impact on a companys bottom line, as losing customers means losing potential revenue and the need to acquire new customers to sustain growth.')
|
29 |
+
st.write('There are various reasons why customers churn. It could be due to dissatisfaction with the product or service, poor customer experience, better offers or alternatives from competitors, changes in personal circumstances, or simply a lack of engagement or perceived value. Identifying and understanding the underlying causes of churn is crucial for businesses to develop effective strategies to reduce churn rates')
|
30 |
+
st.write('To mitigate churn, companies employ various retention strategies. These include improving product quality, enhancing customer service and support, personalizing offers and experiences, implementing loyalty programs, and proactively reaching out to at-risk customers. By focusing on customer satisfaction, loyalty, and continuous improvement, businesses can increase customer retention, foster long-term relationships, and ultimately drive sustainable growth.')
|
31 |
+
|
32 |
+
# Membuat garis lurus
|
33 |
+
st.markdown('---')
|
34 |
+
|
35 |
+
st.write('In this page, show simple exploration about Customer Churn')
|
36 |
+
|
37 |
+
# Show DataFrame
|
38 |
+
data = pd.read_csv('https://raw.githubusercontent.com/hilalrd/latihan_b19/master/churn.csv')
|
39 |
+
st.dataframe(data)
|
40 |
+
|
41 |
+
# membuat plot membership category
|
42 |
+
st.write('### Membership Category')
|
43 |
+
fig = plt.figure(figsize=(15, 7))
|
44 |
+
sns.countplot(x=data['membership_category'], palette='hsv')
|
45 |
+
st.pyplot(fig)
|
46 |
+
st.write('There are two types of membership (No Membership and Basic Membership) that dominate')
|
47 |
+
|
48 |
+
# membuat plot avg transaction berdasrkan membercategory
|
49 |
+
st.write('### Average Transaction by Membership Category')
|
50 |
+
fig = plt.figure(figsize=(15, 5))
|
51 |
+
sns.barplot(data=data, x='membership_category', y='avg_transaction_value')
|
52 |
+
plt.title('Value transaction customer');
|
53 |
+
st.pyplot(fig)
|
54 |
+
st.write('the biggest transaction come from Platinum and Premium membership')
|
55 |
+
|
56 |
+
# Membuat Histogram berdasarkan Input user
|
57 |
+
st.write('#### Chose Data Customer Experience')
|
58 |
+
pilihan = st.selectbox('Pilih column : ', ('complaint_status', 'feedback'))
|
59 |
+
fig = plt.figure(figsize=(15, 5))
|
60 |
+
sns.histplot(data[pilihan], bins=30, kde=True)
|
61 |
+
st.pyplot(fig)
|
62 |
+
|
63 |
+
# Membuat Plotly plot
|
64 |
+
st.write('#### Correlation - Point in wallet with Average Transaction')
|
65 |
+
fig = px.scatter(data, x='points_in_wallet', y='avg_transaction_value')
|
66 |
+
st.plotly_chart(fig)
|
67 |
+
|
68 |
+
|
69 |
+
if __name__== '__main__':
|
70 |
+
run()
|
app.py
CHANGED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import EDA
|
3 |
+
import prediction
|
4 |
+
|
5 |
+
navigation = st.sidebar.selectbox('Pilih Halaman : ', ('EDA', 'Predict Customer Churn'))
|
6 |
+
|
7 |
+
if navigation == 'EDA':
|
8 |
+
EDA.run()
|
9 |
+
else:
|
10 |
+
prediction.run()
|
churn_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:66ce4a6e79be5332a868c51fa70f1a2f70b241e4d78bc4e123db53ffca0322d2
|
3 |
+
size 102608
|
final_pipeline.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9c03179224acd13dae7edc60e86b1a74cdd66bd07d47498375f8292b94e9429b
|
3 |
+
size 5208
|
prediction.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import json
|
6 |
+
import datetime
|
7 |
+
import tensorflow as tf
|
8 |
+
from tensorflow.keras.models import load_model
|
9 |
+
|
10 |
+
# Load Models
|
11 |
+
with open('final_pipeline.pkl', 'rb') as file_1:
|
12 |
+
model_pipeline = pickle.load(file_1)
|
13 |
+
|
14 |
+
model_ann = load_model ('churn_model.h5')
|
15 |
+
|
16 |
+
def run():
|
17 |
+
|
18 |
+
with st.form(key='from_fifa_2022'):
|
19 |
+
user_Id = st.text_input('UserID', value='')
|
20 |
+
age = st.number_input('Age', min_value=10, max_value=80, step=1, help='Usia Prediksi')
|
21 |
+
st.write('M = Male | F = Female')
|
22 |
+
gender = st.selectbox('Gender', ('M', 'F'), index=1)
|
23 |
+
region_category = st.selectbox('Region', ('Town', 'City', 'Village'), index=1)
|
24 |
+
membership_category = st.selectbox('Membership', ('No Membership', 'Basic Membership', 'Gold Membership', 'Silver Membership', 'Premium Membership', 'Platinum Membership'), index=1)
|
25 |
+
st.markdown('---')
|
26 |
+
|
27 |
+
joining_date = st.date_input('JoiningDate', datetime.date(2019, 7, 6))
|
28 |
+
joined_through_referral = st.selectbox('Referral', ('Yes', 'No'), index=1)
|
29 |
+
preferred_offer_types = st.selectbox('Offer', ('Gift Vouchers/Coupons', 'Credit/Debit Card Offers', 'Without Offers'), index=1)
|
30 |
+
medium_of_operation = st.selectbox('Devices', ('Desktop', 'Smartphone', 'Both'), index=1)
|
31 |
+
internet_option = st.selectbox('InternetOption', ('Wi-Fi', 'Mobile_Data', 'Fiber_Optic'), index=1)
|
32 |
+
last_visit_time = st.date_input('LastVisit', datetime.date(2019, 7, 6))
|
33 |
+
st.markdown('---')
|
34 |
+
|
35 |
+
days_since_last_login = st.number_input('DaysLastLogin', min_value=1, max_value=100)
|
36 |
+
avg_time_spent = st.number_input('AverageTimeSpent', min_value=1, max_value=1000)
|
37 |
+
avg_transaction_value = st.number_input('Transaction', min_value=1, max_value=100000)
|
38 |
+
avg_frequency_login_days = st.number_input('FrequencyLogin', min_value=1, max_value=31)
|
39 |
+
points_in_wallet = st.number_input('WalletPoint', min_value=10, max_value=10000)
|
40 |
+
st.markdown('---')
|
41 |
+
|
42 |
+
used_special_discount = st.selectbox('UsedDiscount', ('Yes', 'No'), index=1)
|
43 |
+
offer_application_preference = st.selectbox('OfferAplication', ('Yes', 'No'), index=1)
|
44 |
+
past_complaint = st.selectbox('PastComplaint', ('Yes', 'No'), index=1)
|
45 |
+
complaint_status = st.selectbox('ComplaintStatus', ('Not Applicable', 'Unsolved', 'Solved', 'Solved in Follow-up', 'No Information Available'), index=1)
|
46 |
+
feedback = st.selectbox('Feedback', ('Poor Product Quality', 'No reason specified', 'Too many ads', 'Poor Website',
|
47 |
+
'Poor Customer Service', 'Reasonable Price', 'User Friendly Website', 'Products always in Stock', 'Quality Customer Care'), index=1)
|
48 |
+
|
49 |
+
submitted = st.form_submit_button('Prediction')
|
50 |
+
|
51 |
+
data_inf = {
|
52 |
+
'user_Id': user_Id,
|
53 |
+
'age': age,
|
54 |
+
'gender': gender,
|
55 |
+
'region_category': region_category,
|
56 |
+
'membership_category': membership_category,
|
57 |
+
'joining_date': joining_date,
|
58 |
+
'joined_through_referral': joined_through_referral,
|
59 |
+
'preferred_offer_types': preferred_offer_types,
|
60 |
+
'medium_of_operation': medium_of_operation,
|
61 |
+
'internet_option': internet_option,
|
62 |
+
'last_visit_time': last_visit_time,
|
63 |
+
'days_since_last_login': days_since_last_login,
|
64 |
+
'avg_time_spent': avg_time_spent,
|
65 |
+
'avg_transaction_value': avg_transaction_value,
|
66 |
+
'avg_frequency_login_days': avg_frequency_login_days,
|
67 |
+
'points_in_wallet': points_in_wallet,
|
68 |
+
'used_special_discount': used_special_discount,
|
69 |
+
'offer_application_preference': offer_application_preference,
|
70 |
+
'past_complaint': past_complaint,
|
71 |
+
'complaint_status': complaint_status,
|
72 |
+
'feedback': feedback
|
73 |
+
}
|
74 |
+
|
75 |
+
data_inf = pd.DataFrame([data_inf])
|
76 |
+
st.dataframe(data_inf)
|
77 |
+
|
78 |
+
if submitted:
|
79 |
+
# input pipeline
|
80 |
+
data_inf_final = model_pipeline.transform(data_inf)
|
81 |
+
|
82 |
+
# Predict Model
|
83 |
+
y_pred_inf = model_ann.predict(data_inf_final)
|
84 |
+
y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0)
|
85 |
+
if y_pred_inf == 0:
|
86 |
+
hasil_prediksi = "Not Churn"
|
87 |
+
else:
|
88 |
+
hasil_prediksi = "Churn"
|
89 |
+
|
90 |
+
# Print Hasil prediksi
|
91 |
+
st.write('Prediksi Kemungkinan : ', hasil_prediksi)
|
92 |
+
|
93 |
+
if __name__== '__main__':
|
94 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
seaborn
|
4 |
+
matplotlib
|
5 |
+
plotly
|
6 |
+
Pillow
|
7 |
+
tensorflow==2.12.0
|
8 |
+
feature_engine
|
9 |
+
scikit-learn == 1.2.2
|