import streamlit as st import pandas as pd import numpy as np import joblib # Load the trained model def load_model(): return joblib.load("churn_prediction_model_v1_0.joblib") model = load_model() # Streamlit UI for Customer Churn Prediction st.title("Customer Churn Prediction App") st.write("App to predict churn") st.write("Enter Customer details to predict churn") # Collect user input CreditScore = st.number_input("Credit Score", min_value=0, max_value=1000, value=500) Geography = st.selectbox("Geography (country where the customer resides)", ["France", "Germany", "Spain"]) Age = st.number_input("Age (customer's age in years)", min_value=18, max_value=100, value=30) Tenure = st.number_input("Tenure (number of years the customer has been with the bank)", value=12) Balance = st.number_input("Account Balance (customer’s account balance)", min_value=0.0, value=10000.0) NumOfProducts = st.number_input("Number of Products (number of products the customer has with the bank)", min_value=1, value=1) HasCrCard = st.selectbox("Has Credit Card?", ["Yes", "No"]) IsActiveMember = st.selectbox("Is Active Member?", ["Yes", "No"]) EstimatedSalary = st.number_input("Estimated Salary (customer’s estimated salary)", min_value=0.0, value=50000.0) # Convert categorical inputs to match model training input_data = pd.DataFrame([{ 'CreditScore': CreditScore, 'Geography': Geography, 'Age': Age, 'Tenure': Tenure, 'Balance': Balance, 'NumOfProducts': NumOfProducts, 'HasCrCard': 1 if HasCrCard == "Yes" else 0, 'IsActiveMember': 1 if IsActiveMember == "Yes" else 0, 'EstimatedSalary': EstimatedSalary }]) # Set the classification threshold classification_threshold = 0.45 # Predict button if st.button("Predict"): prediction_proba = model.predict_proba(input_data)[0, 1] prediction = (prediction_proba >= classification_threshold).astype(int) result = "churn" if prediction == 1 else "not churn" st.write(f"Based on the information provided, the customer is likely to {result}.")