File size: 2,876 Bytes
66423d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pandas as pd
from tensorflow.keras.models import load_model
import pickle
import streamlit as st


with open('preprocessor.pkl', 'rb') as f:
    preprocessor = pickle.load(f)
    
ann_model = load_model('ann_model.keras')


df = pd.read_csv('customer_churn_1M.csv') 

st.title("ChurnGuard AI: Predict Customer Exit with Deep Learning")
st.image('Customer_Churn_Prediction_-_AI__Analytics___Retention_Tips-1764682187258.webp')

age = st.number_input("Age", min_value=18, max_value=100)
gender = st.selectbox("Gender", df['gender'].unique())
annual_income = st.number_input("Annual Income", min_value=0.0)
education = st.selectbox("Education", df['education'].unique())
marital_status = st.selectbox("Marital Status", df['marital_status'].unique())
dependents= st.number_input("Dependents", min_value=0, max_value=10)
tenure = st.number_input("Tenure", min_value=0, max_value=50)
contract = st.selectbox("Contract Type", df['contract'].unique())
payment_method = st.selectbox("Payment Method", df['payment_method'].unique())
credit_score = st.number_input("Credit Score", min_value=300, max_value=900)

def model():
    input_data = pd.DataFrame([{
        "age": age,
        "gender": gender,
        "annual_income": annual_income,
        "education": education,
        "marital_status": marital_status,
        "dependents": dependents,
        "tenure": tenure,
        "contract": contract,
        "payment_method": payment_method,
        "credit_score": credit_score,

        # 👉 Add ALL missing columns with defaults
        "avg_monthly_gb": 0,
        "has_streaming_tv": "No",
        "customer_age_days": 0,
        "senior_citizen": 0,
        "late_payments": 0,
        "totalcharges": 0,
        "paperless_billing": "No",
        "has_tech_support": "No",
        "has_online_security": "No",
        "monthlycharges": 0,
        "has_device_protection": "No",
        "has_phone_service": "Yes",
        "customer_satisfaction": 3,
        "has_internet_service": "Yes",
        "has_streaming_movies": "No",
        "days_since_last_interaction": 0,
        "num_complaints": 0,
        "has_online_backup": "No",
        "num_service_calls": 0
    }])
    
    data=preprocessor.transform(input_data)
    pred = ann_model.predict(data)
    
    return pred[0][0]
if st.button('predict'):
    result=model()
    
if st.button('predict', key='predict_button'):
    result = model()
    
    if result > 0.5:
        st.error("High Churn Risk Detected!")
        st.markdown("This customer is **likely to leave**. Consider proactive retention strategies like personalized offers or engagement.")
    else:
        st.success(" Customer Retention Likely")
        st.markdown("This customer is **likely to stay**. Maintain engagement to ensure continued satisfaction.")