Py.Cafe

rajatjha728/

telecom-customer-churn-prediction-0

Telecom Customer Churn Prediction

DocsPricing
  • yhu/
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
import numpy as np
import pickle

# Load your trained churn prediction model (ensure this model.pkl is with app.py)
model = pickle.load(open('model.pkl', 'rb'))

st.title("Telecom Customer Churn Prediction")

# User input fields for required features (example features shown, add all needed)
gender = st.selectbox("Gender", ["Male", "Female"])
senior_citizen = st.selectbox("Senior Citizen", [0, 1])
partner = st.selectbox("Partner", ["Yes", "No"])
dependents = st.selectbox("Dependents", ["Yes", "No"])
tenure = st.slider("Tenure (months)", 0, 100, 12)
monthly_charges = st.number_input("Monthly Charges", min_value=0.0, max_value=1000.0, value=70.0)

# Preprocessing input to match model encoding
def preprocess_input():
    features = []
    features.append(1 if gender == "Male" else 0)
    features.append(senior_citizen)
    features.append(1 if partner == "Yes" else 0)
    features.append(1 if dependents == "Yes" else 0)
    features.append(tenure)
    features.append(monthly_charges)
    return np.array(features).reshape(1, -1)

# Prediction on button click
if st.button("Predict Churn"):
    input_features = preprocess_input()
    churn_probability = model.predict_proba(input_features)[0][1]
    st.write(f"Churn Probability: {churn_probability:.2f}")