import streamlit as st
import pandas as pd
import joblib
# Tampilan judul halaman
st.markdown("========================================================================================")
st.markdown("
Welcome to the Churn Prediction Model
", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
st.markdown("========================================================================================")
st.caption(' ')
st.caption('Please enter the customer feature data input on the left side of your screen to get started!')
with st.expander('Input Feature Explanation '):
st.caption('''
|Feature|Explanation|
|---|---|
|Tenure | Tenure of customer in organization|
|Complain | Any complaint has been raised in last month|
|Day Since Last Order | Day Since last order by customer|
|Cashback Amount | Average cashback in last month|
|Number Of Device Registered | Total number of deceives is registered on particular customer|
|Satisfaction Score | Satisfactory score of customer on service|
|Prefered Order Cat | Preferred order category of customer in last month|
|Marital Status | Marital status of customer|
''')
st.sidebar.markdown("===================================")
st.sidebar.markdown("Input Data Customer
", unsafe_allow_html=True)
st.sidebar.markdown("
", unsafe_allow_html=True)
st.sidebar.markdown("===================================")
def user_input():
tenure = st.sidebar.slider('Tenure', min_value=0, max_value=60, value=30)
complain = st.sidebar.selectbox('Complain', ['none', 'any'])
day_since_last_order = st.sidebar.slider('Days Since Last Order', min_value=0, max_value=365, value=30)
cashback_amount = st.sidebar.slider('Cashback Amount', min_value=0, max_value=1000, value=500)
number_of_device_registered = st.sidebar.slider('Number of Devices Registered', min_value=0, max_value=6, value=3)
satisfaction_score = st.sidebar.slider('Satisfaction Score', min_value=1, max_value=5, value=3)
prefered_order_cat = st.sidebar.selectbox('Preferred Order Category', ['Laptop & Accessory', 'Mobile', 'Mobile Phone',
'Others','Fashion', 'Grocery'])
marital_status = st.sidebar.selectbox('Marital Status', ['Single', 'Married', 'Divorced'])
if complain == 'none' :
complain = 0
else :
complain = 1
data = {
'tenure': tenure,
'complain' : complain,
'day_since_last_order': day_since_last_order,
'cashback_amount': cashback_amount,
'number_of_device_registered': number_of_device_registered,
'satisfaction_score': satisfaction_score,
'prefered_order_cat': prefered_order_cat,
'marital_status': marital_status,
}
features = pd.DataFrame(data, index=[0])
return features
# Menjalankan fungsi input pengguna
input = user_input()
# Menampilkan hasil input pengguna dalam bentuk tabel
st.markdown("User Input Result
", unsafe_allow_html=True)
st.table(input)
# Memuat model yang telah disimpan sebelumnya
load_model = joblib.load("model_xgb.pkl")
# Tombol untuk memprediksi
if st.button("Predict", help='Click me!'):
# Melakukan prediksi menggunakan model
prediction = load_model.predict(input)
# Menampilkan hasil prediksi
if prediction == 1:
prediction = 'The customer is likely to churn'
else:
prediction = 'The customer is likely to stay'
st.markdown("Based on the information provided by the user, the model predicts:
", unsafe_allow_html=True)
st.markdown(f"{prediction}
", unsafe_allow_html=True)
# Menampilkan hasil tambahan jika input termasuk dalam salah satu jenis fraud
if prediction != "The customer is likely to stay":
st.warning('This customer falls into the churn category. Please take appropriate action to retain the customer')