ChurnModelling / app.py
amaanadeen's picture
Update app.py
185e396
import streamlit as st
import numpy as np
import pickle5 as pkl
import sklearn
model = pkl.load(open("model.pkl", "rb"))
st.title("Churn Modelling")
st.sidebar.header("Enter the customer details:")
# Credit Score
credit_score = st.sidebar.number_input("Credit Score", min_value=0, max_value=1000)
# Age
age = st.sidebar.number_input("Age", min_value=0, max_value=100)
# Tenure
tenure = st.sidebar.number_input("Tenure", min_value=0, max_value=100)
# Balance
balance = st.sidebar.number_input("Balance", min_value=0, max_value=100000)
# Num of Products
num_of_products = st.sidebar.number_input("Num of Products", min_value=0, max_value=10)
# Has Cr Card
has_cr_card = st.sidebar.radio("Has Cr Card", ("Yes", "No"))
if has_cr_card == "Yes":
has_cr_card = 1
else:
has_cr_card = 0
# Is Active Member
is_active_member = st.sidebar.radio("Is Active Member", ("Yes", "No"))
if is_active_member == "Yes":
is_active_member = 1
else:
is_active_member = 0
# Estimated Salary
estimated_salary = st.sidebar.number_input("Estimated Salary", min_value=0, max_value=100000)
# Female
gender = st.sidebar.selectbox("Enter your gender", ("Male", "Female"))
country = st.sidebar.selectbox("Enter your Country", ("france", "Spain", "germany"))
# Predict the customer's churn status
if st.sidebar.button("Predict"):
if gender == "Male":
female, male = 0, 1
elif gender == "Female":
female, male = 1, 0
if country == "france":
france, germany, spain = 1, 0, 0
elif country == "germany":
france, germany, spain = 0, 1, 0
else:
france, germany, spain = 0, 0, 1
features = [credit_score, age, tenure, balance, num_of_products, has_cr_card, is_active_member, estimated_salary,
female, male, france, germany, spain]
prediction = model.predict([features])
# Display the prediction
if prediction == 1:
st.write("The customer is predicted to exit the bank")
else:
st.write("the customer will not exit the bank")