Commit Deployment Final
Browse files- README.md +12 -0
- __pycache__/eda.cpython-310.pyc +0 -0
- __pycache__/prediction.cpython-310.pyc +0 -0
- app.py +29 -0
- column_transformer.pkl +3 -0
- eda.py +194 -0
- functional_model.keras +0 -0
- prediction.py +183 -0
- requirements.txt +10 -0
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Laptop Price Prediction
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.21.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
__pycache__/eda.cpython-310.pyc
ADDED
|
Binary file (4.61 kB). View file
|
|
|
__pycache__/prediction.cpython-310.pyc
ADDED
|
Binary file (4.3 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import eda
|
| 3 |
+
import prediction
|
| 4 |
+
from streamlit_option_menu import option_menu
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
st.sidebar.header("HaiMeds Customer Churn Prediction")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with st.sidebar:
|
| 11 |
+
st.write("Ediashta Revindra - FTDS-020")
|
| 12 |
+
selected = option_menu(
|
| 13 |
+
"Menu",
|
| 14 |
+
[
|
| 15 |
+
"Distribution",
|
| 16 |
+
"Correlation Matrix",
|
| 17 |
+
"Regression",
|
| 18 |
+
],
|
| 19 |
+
icons=["bar-chart", "link-45deg", "code-square"],
|
| 20 |
+
menu_icon="cast",
|
| 21 |
+
default_index=0,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if selected == "Distribution":
|
| 25 |
+
eda.distribution()
|
| 26 |
+
elif selected == "Correlation Matrix":
|
| 27 |
+
eda.corr_matrix()
|
| 28 |
+
elif selected == "Regression":
|
| 29 |
+
prediction.predict()
|
column_transformer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25e90257db3cb67cf0c961fac606fbc5a90ee7a79b02d6a4329abe4c53667783
|
| 3 |
+
size 3983
|
eda.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import seaborn as sns
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="Laptop Price Regression",
|
| 8 |
+
layout="wide",
|
| 9 |
+
initial_sidebar_state="expanded",
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# dataset
|
| 13 |
+
dataset = "https://raw.githubusercontent.com/ediashta/p2-ftds020-rmt-m1/main/churn.csv"
|
| 14 |
+
data = pd.read_csv(dataset)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def distribution():
|
| 18 |
+
# distribution plot
|
| 19 |
+
st.title("HaiMeds Customer Distribution")
|
| 20 |
+
col1, col2 = st.columns(2)
|
| 21 |
+
|
| 22 |
+
hist_plot_1 = col1.selectbox(
|
| 23 |
+
"Choose Table",
|
| 24 |
+
("Age", "Last Login (Days)", "Avg. Time Spent"),
|
| 25 |
+
)
|
| 26 |
+
hist_plot(hist_plot_1, col1)
|
| 27 |
+
|
| 28 |
+
hist_plot_2 = col2.selectbox(
|
| 29 |
+
"Choose Table",
|
| 30 |
+
("Avg. Transaction", "Avg. Login Frequency (Days)", "Points"),
|
| 31 |
+
)
|
| 32 |
+
hist_plot(hist_plot_2, col2)
|
| 33 |
+
|
| 34 |
+
col1, col2 = st.columns(2)
|
| 35 |
+
bar_plot_1 = col1.selectbox(
|
| 36 |
+
"Choose Table",
|
| 37 |
+
("Gender", "Region", "Membership", "Referral", "Preferred Offer", "Devices"),
|
| 38 |
+
)
|
| 39 |
+
bar_plot(bar_plot_1, col1)
|
| 40 |
+
|
| 41 |
+
bar_plot_2 = col2.selectbox(
|
| 42 |
+
"Choose Table",
|
| 43 |
+
(
|
| 44 |
+
"Internet",
|
| 45 |
+
"Used Discount",
|
| 46 |
+
"Offer Application Preference",
|
| 47 |
+
"Past Complaint",
|
| 48 |
+
"Complaint Status",
|
| 49 |
+
"Feedback",
|
| 50 |
+
),
|
| 51 |
+
)
|
| 52 |
+
bar_plot(bar_plot_2, col2)
|
| 53 |
+
|
| 54 |
+
st.subheader("Churn Risk Score Distribution")
|
| 55 |
+
churn_score()
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def corr_matrix():
|
| 59 |
+
# distribution plot
|
| 60 |
+
st.title("Features Correlation")
|
| 61 |
+
col1, col2 = st.columns([7, 5])
|
| 62 |
+
|
| 63 |
+
# correlation for numerical
|
| 64 |
+
fig = plt.figure(figsize=(10, 10))
|
| 65 |
+
corr_matrix = data[
|
| 66 |
+
[
|
| 67 |
+
"age",
|
| 68 |
+
"days_since_last_login",
|
| 69 |
+
"avg_time_spent",
|
| 70 |
+
"avg_transaction_value",
|
| 71 |
+
"avg_frequency_login_days",
|
| 72 |
+
"points_in_wallet",
|
| 73 |
+
"churn_risk_score",
|
| 74 |
+
]
|
| 75 |
+
].corr(method="spearman")
|
| 76 |
+
sns.heatmap(corr_matrix, annot=True, cmap="mako", square=True)
|
| 77 |
+
plt.xticks(rotation=45)
|
| 78 |
+
plt.yticks(rotation=45)
|
| 79 |
+
col1.pyplot(fig)
|
| 80 |
+
|
| 81 |
+
feature_importance_info = """
|
| 82 |
+
**Feature Importance:**
|
| 83 |
+
|
| 84 |
+
- **gender:** 0.0
|
| 85 |
+
- **region_category:** 0.0223
|
| 86 |
+
- **membership_category:** 0.7859
|
| 87 |
+
- **joining_date:** 0.0
|
| 88 |
+
- **joined_through_referral:** 0.0355
|
| 89 |
+
- **preferred_offer_types:** 0.0434
|
| 90 |
+
- **medium_of_operation:** 0.0218
|
| 91 |
+
- **internet_option:** 0.0025
|
| 92 |
+
- **last_visit_time:** 0.0604
|
| 93 |
+
- **used_special_discount:** 0.0092
|
| 94 |
+
- **offer_application_preference:** 0.0179
|
| 95 |
+
- **past_complaint:** 0.0072
|
| 96 |
+
- **complaint_status:** 0.0054
|
| 97 |
+
- **feedback:** 0.4561
|
| 98 |
+
"""
|
| 99 |
+
col2.markdown(feature_importance_info)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def bar_plot(var, col):
|
| 103 |
+
# ram storage dist
|
| 104 |
+
col.write("Distribusi " + var + " terbanyak")
|
| 105 |
+
var_old = var
|
| 106 |
+
|
| 107 |
+
if var == "Gender":
|
| 108 |
+
var = "gender"
|
| 109 |
+
elif var == "Region":
|
| 110 |
+
var = "region_category"
|
| 111 |
+
elif var == "Membership":
|
| 112 |
+
var = "membership_category"
|
| 113 |
+
elif var == "Referral":
|
| 114 |
+
var = "joined_through_referral"
|
| 115 |
+
elif var == "Preferred Offer":
|
| 116 |
+
var = "preferred_offer_types"
|
| 117 |
+
elif var == "Devices":
|
| 118 |
+
var = "medium_of_operation"
|
| 119 |
+
elif var == "Internet":
|
| 120 |
+
var = "internet_option"
|
| 121 |
+
elif var == "Used Discount":
|
| 122 |
+
var = "used_special_discount"
|
| 123 |
+
elif var == "Offer Application Preference":
|
| 124 |
+
var = "offer_application_preference"
|
| 125 |
+
elif var == "Past Complaint":
|
| 126 |
+
var = "past_complaint"
|
| 127 |
+
elif var == "Complaint Status":
|
| 128 |
+
var = "complaint_status"
|
| 129 |
+
elif var == "Feedback":
|
| 130 |
+
var = "feedback"
|
| 131 |
+
|
| 132 |
+
fig = plt.figure(figsize=(10, 5))
|
| 133 |
+
ax1 = sns.countplot(
|
| 134 |
+
data=data,
|
| 135 |
+
x=var,
|
| 136 |
+
palette="mako",
|
| 137 |
+
)
|
| 138 |
+
plt.xlabel(var_old)
|
| 139 |
+
ax1.bar_label(container=ax1.containers[0], labels=data[var].value_counts().values)
|
| 140 |
+
col.pyplot(fig)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def hist_plot(var, col):
|
| 144 |
+
# check price distribution
|
| 145 |
+
col.write("Distribusi " + var)
|
| 146 |
+
var_old = var
|
| 147 |
+
|
| 148 |
+
if var == "Age":
|
| 149 |
+
var = "age"
|
| 150 |
+
elif var == "Last Login (Days)":
|
| 151 |
+
var = "days_since_last_login"
|
| 152 |
+
elif var == "Avg. Time Spent":
|
| 153 |
+
var = "avg_time_spent"
|
| 154 |
+
elif var == "Avg. Transaction":
|
| 155 |
+
var = "avg_transaction_value"
|
| 156 |
+
elif var == "Avg. Login Frequency (Days)":
|
| 157 |
+
var = "avg_frequency_login_days"
|
| 158 |
+
elif var == "Points":
|
| 159 |
+
var = "points_in_wallet"
|
| 160 |
+
else:
|
| 161 |
+
var = var
|
| 162 |
+
|
| 163 |
+
fig = plt.figure(figsize=(10, 5))
|
| 164 |
+
|
| 165 |
+
palette = sns.color_palette("mako_r", 50)
|
| 166 |
+
plt.xlabel(var_old)
|
| 167 |
+
plot = sns.histplot(data=data, x=var, kde=True, bins=50, color="teal")
|
| 168 |
+
|
| 169 |
+
for bin_, i in zip(plot.patches, palette):
|
| 170 |
+
bin_.set_facecolor(i)
|
| 171 |
+
|
| 172 |
+
col.pyplot(fig)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def churn_score():
|
| 176 |
+
fig = plt.figure(figsize=(20, 5))
|
| 177 |
+
plt.ylabel("Churn Risk Score")
|
| 178 |
+
|
| 179 |
+
sorted_scores = data["churn_risk_score"].value_counts().sort_index(ascending=False)
|
| 180 |
+
ax = sns.countplot(
|
| 181 |
+
data=data, y="churn_risk_score", palette="mako", order=sorted_scores.index
|
| 182 |
+
)
|
| 183 |
+
# Get the value counts for each category of 'churn_risk_score'
|
| 184 |
+
value_counts = data["churn_risk_score"].value_counts()
|
| 185 |
+
|
| 186 |
+
# Add labels on top of each bar
|
| 187 |
+
for idx, count in enumerate(value_counts):
|
| 188 |
+
ax.text(count + 5, idx, str(count), va="center")
|
| 189 |
+
|
| 190 |
+
st.pyplot(fig)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
if __name__ == "__main__":
|
| 194 |
+
distribution()
|
functional_model.keras
ADDED
|
Binary file (37.1 kB). View file
|
|
|
prediction.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 8 |
+
# load file
|
| 9 |
+
|
| 10 |
+
with open("./column_transformer.pkl", "rb") as file_1:
|
| 11 |
+
column_transformer = pickle.load(file_1)
|
| 12 |
+
|
| 13 |
+
model_functional = load_model("./functional_model.keras")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def predict():
|
| 17 |
+
# form
|
| 18 |
+
with st.form("key=churn_prediction"):
|
| 19 |
+
st.subheader("Churn Score Prediction")
|
| 20 |
+
|
| 21 |
+
st.markdown("**Customer Data**")
|
| 22 |
+
|
| 23 |
+
col1, col2 = st.columns(2, gap="large")
|
| 24 |
+
age = col1.number_input(label="Age", help="Customer Age", step=1, value=20)
|
| 25 |
+
|
| 26 |
+
membership = col2.selectbox(
|
| 27 |
+
label="Membership Category",
|
| 28 |
+
options=(
|
| 29 |
+
"No Membership",
|
| 30 |
+
"Basic Membership",
|
| 31 |
+
"Premium Membership",
|
| 32 |
+
"Silver Membership",
|
| 33 |
+
"Gold Membership",
|
| 34 |
+
"Platinum Membership",
|
| 35 |
+
),
|
| 36 |
+
)
|
| 37 |
+
st.markdown("---")
|
| 38 |
+
|
| 39 |
+
col1, col2, col3, col4 = st.columns(4, gap="large")
|
| 40 |
+
region = col1.radio(
|
| 41 |
+
label="Region",
|
| 42 |
+
help="Customer Residence Region",
|
| 43 |
+
options=("Town", "City", "Village"),
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
referral = col2.radio(
|
| 47 |
+
label="Referral", help="Joined Through Referral?", options=("Yes", "No")
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
device = col3.radio(
|
| 51 |
+
label="Device(s)",
|
| 52 |
+
help="Device Used",
|
| 53 |
+
options=("Smartphone", "Desktop", "Both"),
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
internet = col4.radio(
|
| 57 |
+
label="Internet Connection", options=("Wi-Fi", "Fiber_Optic", "Mobile_Data")
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
st.markdown("---")
|
| 61 |
+
|
| 62 |
+
st.markdown("**Customer Behavior**")
|
| 63 |
+
col1, col2, col3, col4, col5 = st.columns(5, gap="large")
|
| 64 |
+
|
| 65 |
+
last_login = col1.number_input(
|
| 66 |
+
label="Last Login", help="Days Since Last Login", step=1, value=6
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
avg_time = col2.number_input(
|
| 70 |
+
label="Avg. Usage Time", help="Average Usage Time (Minutes)", value=30
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
avg_login = col3.number_input(
|
| 74 |
+
label="Avg. Login Frequency",
|
| 75 |
+
help="Average Login Frequency (Days)",
|
| 76 |
+
value=14,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
points = col4.number_input(label="Points in Wallet", value=300)
|
| 80 |
+
|
| 81 |
+
transaction = col5.number_input(label="Avg. Transaction", value=100, help="USD")
|
| 82 |
+
|
| 83 |
+
st.markdown("---")
|
| 84 |
+
|
| 85 |
+
col1, col2, col3 = st.columns(3, gap="large")
|
| 86 |
+
|
| 87 |
+
offer_pref = col1.selectbox(
|
| 88 |
+
label="Preferred Offer Type",
|
| 89 |
+
options=(
|
| 90 |
+
"Gift Vouchers/Coupons",
|
| 91 |
+
"Credit/Debit Card Offers",
|
| 92 |
+
"Without Offers",
|
| 93 |
+
),
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
used_disc = col2.radio(label="Used Discount Before?", options=("Yes", "No"))
|
| 97 |
+
|
| 98 |
+
offer_app = col3.radio(
|
| 99 |
+
label="Application Preference Offer?", options=("Yes", "No")
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
st.markdown("---")
|
| 103 |
+
col1, col2, col3 = st.columns(3, gap="large")
|
| 104 |
+
|
| 105 |
+
complaints = col1.radio(label="Past Complaint?", options=("Yes", "No"))
|
| 106 |
+
|
| 107 |
+
complaints_status = col2.selectbox(
|
| 108 |
+
label="Complaint Status",
|
| 109 |
+
options=(
|
| 110 |
+
"Not Appllicable",
|
| 111 |
+
"Unsolved",
|
| 112 |
+
"Solved",
|
| 113 |
+
"Solved in Follow-up",
|
| 114 |
+
"No Information Available",
|
| 115 |
+
),
|
| 116 |
+
)
|
| 117 |
+
feedback = col3.selectbox(
|
| 118 |
+
label="Feedback Type", options=("Neutral", "Positive", "Negative")
|
| 119 |
+
)
|
| 120 |
+
submitted = st.form_submit_button("Predict")
|
| 121 |
+
|
| 122 |
+
# inferencing
|
| 123 |
+
data_inf = [
|
| 124 |
+
{
|
| 125 |
+
"age": age,
|
| 126 |
+
"region_category": region,
|
| 127 |
+
"membership_category": membership,
|
| 128 |
+
"joined_through_referral": referral,
|
| 129 |
+
"preferred_offer_types": offer_pref,
|
| 130 |
+
"medium_of_operation": device,
|
| 131 |
+
"internet_option": internet,
|
| 132 |
+
"days_since_last_login": last_login,
|
| 133 |
+
"avg_time_spent": avg_time,
|
| 134 |
+
"avg_transaction_value": transaction,
|
| 135 |
+
"avg_frequency_login_days": avg_login,
|
| 136 |
+
"points_in_wallet": points,
|
| 137 |
+
"used_special_discount": used_disc,
|
| 138 |
+
"offer_application_preference": offer_app,
|
| 139 |
+
"past_complaint": complaints,
|
| 140 |
+
"complaint_status": complaints_status,
|
| 141 |
+
"feedback": feedback,
|
| 142 |
+
}
|
| 143 |
+
]
|
| 144 |
+
|
| 145 |
+
data_inf = pd.DataFrame(data_inf)
|
| 146 |
+
|
| 147 |
+
st.dataframe(data_inf)
|
| 148 |
+
|
| 149 |
+
data_inf_transform = column_transformer.transform(data_inf)
|
| 150 |
+
y_pred_inf = model_functional.predict(data_inf_transform)
|
| 151 |
+
y_pred_inf = np.where(y_pred_inf >= 0.65, 1, 0)
|
| 152 |
+
|
| 153 |
+
st.write("Prediksi Churn Pelanggan Tersebut adalah :")
|
| 154 |
+
if y_pred_inf[0] == 1:
|
| 155 |
+
html_str = f"""
|
| 156 |
+
<style>
|
| 157 |
+
p.a {{
|
| 158 |
+
font: bold 36px Arial;
|
| 159 |
+
color: teal;
|
| 160 |
+
}}
|
| 161 |
+
</style>
|
| 162 |
+
<p class="a">Pelanggan Tidak Berpotensi Churn</p>
|
| 163 |
+
"""
|
| 164 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
| 165 |
+
st.write(
|
| 166 |
+
"Dapat menekankan program loyalty agar pelanggan tetap menggunakan layanan"
|
| 167 |
+
)
|
| 168 |
+
else:
|
| 169 |
+
html_str = f"""
|
| 170 |
+
<style>
|
| 171 |
+
p.a {{
|
| 172 |
+
font: bold 36px Arial;
|
| 173 |
+
color: red;
|
| 174 |
+
}}
|
| 175 |
+
</style>
|
| 176 |
+
<p class="a">Pelanggan Berpotensi Churn</p>
|
| 177 |
+
"""
|
| 178 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
| 179 |
+
st.write("Dapat diberikan promosi untuk menarik pelanggan kembali")
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
if __name__ == "__main__":
|
| 183 |
+
predict()
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seaborn
|
| 2 |
+
pandas
|
| 3 |
+
matplotlib
|
| 4 |
+
plotly
|
| 5 |
+
Pillow
|
| 6 |
+
scikit-learn==1.2.2
|
| 7 |
+
category_encoders
|
| 8 |
+
xgboost
|
| 9 |
+
streamlit_option_menu
|
| 10 |
+
tensorflow
|