anjasafm's picture
Upload 6 files
98aa7cd verified
raw
history blame
No virus
2.25 kB
import streamlit as st
import pandas as pd
import pickle
# Load the trained model
with open('model_xgb.pkl', 'rb') as file_1:
model_inf_xgb = pickle.load(file_1)
# Function to run the Streamlit app
def run():
# Set page title and sidebar image
st.write('๐Ÿ”ฎ Customer Churn ๐Ÿ”ฎ')
# Introduction
st.subheader("๐Ÿ“Š Prediction of Customer Churn")
st.write("Welcome to the Customer Churn Predictor app! This app predicts whether a customer will Churn on their subscription based on provided information.")
# Input form
st.markdown('## ๐Ÿ“ Input Data')
with st.form('my_form'):
# Input fields
Age = st.number_input('๐Ÿ’ณ Age', min_value=0.0, max_value=65.0)
st.markdown('**Gender:** Male And Female')
Gender = st.selectbox('๐Ÿšป Gender', options=['Male', 'Female'])
Tenure = st.number_input('๐Ÿ’ณ Tenure', min_value=0.0, max_value=60.0)
Usage_Frequency = st.number_input('Usage Frequency', min_value=0.0, max_value=30.0)
Support_Calls = st.number_input('Support Calls', min_value=0.0, max_value=10.0)
Payment_Delay = st.number_input('Payment Delay', min_value=0.0, max_value=30.0)
Subscription_Type = st.selectbox('Subscription Type', options=['Basic', 'Standard', 'Premium'])
Contract_length = st.selectbox('Subscription Type', options=['Monthly', 'Annual', 'Quarterly'])
Total_Spend = st.number_input('Total Spend', min_value=100.0, max_value=1000.0)
submitted = st.form_submit_button('๐Ÿ” Let\'s Check!')
# Create DataFrame from user input
data = {
'Age': Age,
'Gender': Gender,
'Tenure' : Tenure,
'Usage Frequency' : Usage_Frequency,
'Support Calls': Support_Calls,
'Payment Delay' : Payment_Delay,
'Subscription Type' : Subscription_Type,
'Contract Length' : Contract_length,
'Total Spend' : Total_Spend
}
df = pd.DataFrame([data])
st.dataframe(df)
# Make prediction
if submitted:
prediction = model.predict(df)
# Display prediction result
if prediction[0] == 0:
st.write('๐ŸŸข Not Churn')
else:
st.write('๐Ÿ”ด Churn')
if __name__== '__main__':
run()