File size: 1,393 Bytes
c741b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import pandas as pd
import os
from joblib import load

# --- Model Loading ---
@st.cache_resource
def load_model():
    model_path = "customer_churn_pipeline.joblib"  # same folder
    if not os.path.exists(model_path):
        st.error(f"Model file not found: {model_path}")
        st.stop()
    try:
        pipeline = load(model_path)
    except Exception as e:
        st.error(f"Failed to load model: {e}")
        st.stop()
    return pipeline

pipeline = load_model()

# --- Streamlit UI ---
st.title("Credit Card Customer Churn Prediction")
st.write("Adjust the input values below to predict whether a customer will churn:")

# Numeric inputs
customer_age = st.slider("Customer Age", 18, 100, 30)
credit_limit = st.slider("Credit Limit", 0, 100000, 5000, step=100)

# Categorical input
gender = st.selectbox("Gender", ["Female", "Male"])

# Build input dataframe
input_data = pd.DataFrame({
    'Customer_Age': [customer_age],
    'Credit_Limit': [credit_limit],
    'Gender': [gender]
})

# Predict button
if st.button("Predict Churn"):
    prediction = pipeline.predict(input_data)[0]
    probability = pipeline.predict_proba(input_data)[0][1]

    if prediction == 1:
        st.warning(f"⚠️ Customer is likely to churn! Probability: {probability:.2%}")
    else:
        st.success(f"✅ Customer is not likely to churn. Probability: {probability:.2%}")