Churn_Pred / app.py
MVesalA's picture
Upload 2 files
40f117a verified
raw
history blame
2.51 kB
import streamlit as st
import numpy as np
import pandas as pd
import joblib
model = joblib.load('Churn_Pred/Churn_PredCls.joblib')
gender = st.selectbox("Choose sex", ['Male', 'Female'])
SeniorCitizen = st.sidebar.selectbox("SeniorCitizen", ['Yes', 'No'])
Partner = st.sidebar.selectbox("Does he/she have partner?", ['Yes', 'No'])
Dependents = st.sidebar.selectbox("Dependents", ['Yes', 'No'])
tenure = st.slider("Choose tenure", 0, 100)
PhoneService = st.sidebar.selectbox("PhoneService", ['Yes', 'No'])
MultipleLines = st.sidebar.selectbox("MultipleLines", ['Yes', 'No'])
InternetService = st.selectbox("InternetService", ['DSL', 'Fiber optic', 'No'])
OnlineSecurity = st.sidebar.selectbox("OnlineSecurity", ['Yes', 'No'])
OnlineBackup = st.sidebar.selectbox("OnlineBackup", ['Yes', 'No'])
DeviceProtection = st.sidebar.selectbox("DeviceProtection", ['Yes', 'No'])
TechSupport = st.sidebar.selectbox("TechSupport", ['Yes', 'No'])
StreamingTV = st.sidebar.selectbox("StreamingTV", ['Yes', 'No'])
StreamingMovies = st.sidebar.selectbox("StreamingMovies", ['Yes', 'No'])
Contract = st.selectbox("Contract", ['Month-to-month', 'One year', 'Two year'])
PaperlessBilling = st.sidebar.selectbox("PaperlessBilling", ['Yes', 'No'])
PaymentMethod = st.selectbox("PaymentMethod", ['Electronic check', 'Mailed check', 'Bank transfer (automatic)', 'Credit card (automatic)'])
MonthlyCharges = st.slider("MonthlyCharges", 0, 1000)
TotalCharges = st.slider("TotalCharges", 0, 10000)
columns = ['gender', 'SeniorCitizen', 'Partner', 'Dependents', 'tenure',
'PhoneService', 'MultipleLines', 'InternetService', 'OnlineSecurity',
'OnlineBackup', 'DeviceProtection', 'TechSupport', 'StreamingTV',
'StreamingMovies', 'Contract', 'PaperlessBilling', 'PaymentMethod',
'MonthlyCharges', 'TotalCharges']
rows = [gender, SeniorCitizen, Partner, Dependents, tenure,
PhoneService, MultipleLines, InternetService, OnlineSecurity, OnlineBackup,
DeviceProtection, TechSupport, StreamingTV, StreamingMovies, Contract,
PaperlessBilling, PaymentMethod, MonthlyCharges, TotalCharges]
def predict():
row = np.array(rows)
X = pd.DataFrame([row], columns = columns)
prediction = model.predict(X)
if prediction[0] == 1:
st.success('She/He will remain among the customers :thumbsup:')
else:
st.error('She/He will not remain among the customers :thumbsup:')
trigger = st.button('Predict', on_click=predict)