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}")