Spaces:
Sleeping
Sleeping
File size: 4,568 Bytes
e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca 35caaaa e1954ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import time
import seaborn as sns
import matplotlib.pyplot as plt
import tensorflow as tf
page_bg_img = """
<style>[data-testid="stAppViewContainer"]{
background-color: #d1d1e6;
opacity: 0.2;
background-image: repeating-radial-gradient( circle at 0 0, transparent 0, #d1d1e6 10px ), repeating-linear-gradient( #444cf755, #444cf7 );
}
[data-testid="stHeader"]{
background-color: rgba(0,0,0,0);
}
</style>
"""
Home, Eda, App = st.tabs(['Home', 'Eda', 'App'])
with Home:
st.title("P2 Milestone 1 - Create a Robust Costumer Churn Prediction")
st.subheader("Problem Statement")
st.write('Create a robust costumer churn prediction to directly intialize and handle the appropriate actions to prevent costumers leaving our services')
st.image('Customer-Churn.PNG')
with Eda:
st.title("Exploratory Data Analysis")
dataset = st.container()
analysis = st.container()
conclusion = st.container()
with dataset:
st.subheader("Dataset")
st.Write("The dataset is related to customer churn prediction, where the goal is to predict whether a customer is likely to churn based on the given features. Machine learning models can be trained on this dataset to predict the churn risk of customers, helping businesses take appropriate actions to retain customers and improve customer satisfaction.")
df = pd.read_csv('churn.csv')
st.dataframe(df)
with analysis:
imbalance = st.container()
member = st.container()
behavior_1 = st.container()
behavior_2 = st.container()
behavior_3 = st.container()
correlation = st.container()
st.subheader("Data Overview")
with imbalance:
st.subheader("Imbalance Data Target")
sns.countplot(data=df, x='churn_risk_score', hue='churn_risk_score')
with member:
st.subheader("Membership")
sns.countplot(data=df, x='membership_category', hue='churn_risk_score')
plt.xticks(rotation=45, ha='right')
plt.show
st.subheader("Customer Behavior")
with behavior_1:
sns.countplot(data=df, x='preferred_offer_types', hue='churn_risk_score')
plt.xticks(rotation=45, ha='right')
plt.show
with behavior_2:
sns.countplot(data=df, x='medium_of_operation', hue='churn_risk_score')
plt.xticks(rotation=45, ha='right')
plt.show
with behavior_3:
sns.countplot(data=df, x='internet_option', hue='churn_risk_score')
plt.xticks(rotation=45, ha='right')
plt.show
st.write("Costumer are more likely to churn if choose option without offer, Medium of operation using smartphone is more likely to churn but not significanly different with dekstop user and it seems that is no indication between internet option")
with correlation:
st.subheader("Numeric Correlation")
fig,ax = plt.subplots(figsize=[20,15])
corr = df.corr()
ax = sns.heatmap(corr,annot=True)
plt.show()
with App:
st.subheader("Churn Prediction")
model_tf = tf.keras.models.load_model("model_best.hdf5")
preprocess = joblib.load('full_pipeline.pkl')
df = pd.read_csv('churn.csv')
user_id = st.text_input('Your ID')
age = st.slider('age', 0,100)
membership_category = st.selectbox('membership',['No Membership', 'Basic Membership','Silver Membership', 'Gold Membership', 'Premium Membership', 'Platinum Membership'])
avg_transaction_value = st.slider('avg_transaction_value', 0,999999)
avg_frequency_login_days = st.slider('avg_frequency_login_days', 0, 24)
points_in_wallet = st.slider('points_in_wallet',0,9999999)
feedback = st.selectbox('membership',['No reason specified', 'Poor Customer Service','Poor Product Quality', 'Poor Website', 'Products always in Stock', 'Quality Customer Care','Reasonable Price', 'Too many ads', 'User Friendly Website'])
data = {
'user_id': user_id,
'age': age,
'membership_category': membership_category,
'avg_transaction_value': avg_transaction_value,
'avg_frequency_login_days': avg_frequency_login_days,
'points_in_wallet': points_in_wallet,
'feedback': feedback,
}
input = pd.DataFrame(data, index=[0])
st.subheader('User Input')
st.write(input)
if st.button('Predict'):
process = preprocess.transform(input)
prediction = model_tf.predict(input)
if prediction == 1:
prediction = 'Churn'
else:
prediction = 'Not Churn'
st.write('Based on user input, the placement model predicted: ')
st.write(prediction)
|