Predicts whether a telecom customer is likely to churn (leave the company) using their account, billing, and service data — with a full ML pipeline and an interactive prediction dashboard.
Customer churn is one of the most direct levers on revenue for subscription-based businesses. This project builds and compares five classification models to predict churn probability from customer attributes such as tenure, contract type, payment method, monthly charges, and subscribed services — then ships the best model behind a Streamlit dashboard for real-time, per-customer predictions.
Dataset: Telco Customer Churn — 7,043 customers, 21 features (Kaggle).
Five models were trained and evaluated on a held-out 20% test set, with 5-fold stratified cross-validation for robustness:
| Model | Accuracy | Precision | Recall | F1 | ROC-AUC |
|---|---|---|---|---|---|
| Random Forest 🏆 | 0.762 | 0.537 | 0.765 | 0.631 | 0.844 |
| Logistic Regression | 0.738 | 0.504 | 0.789 | 0.615 | 0.843 |
| LightGBM | 0.750 | 0.519 | 0.778 | 0.623 | 0.841 |
| XGBoost | 0.751 | 0.520 | 0.789 | 0.627 | 0.838 |
| Decision Tree | 0.736 | 0.502 | 0.816 | 0.621 | 0.830 |
Random Forest was selected as the final model (highest ROC-AUC). Class imbalance (~27% churn rate) was handled via class_weight='balanced' / scale_pos_weight rather than resampling, to keep the pipeline simple and avoid synthetic data.
Top churn drivers identified via feature importance: contract type (month-to-month vs. long-term), tenure, internet service type (fiber optic), monthly charges, and payment method (electronic check).
churn_project/
├── data/
│ └── telco_churn.csv # Raw dataset
├── notebook/
│ └── Customer_Churn_Prediction.ipynb # Full pipeline: EDA → FE → modeling → evaluation
├── models/ # Generated after running the notebook
│ ├── churn_model.pkl
│ ├── scaler.pkl
│ ├── feature_columns.pkl
│ ├── numeric_features.pkl
│ └── needs_scaling.pkl
├── app/
│ └── app.py # Streamlit dashboard
├── requirements.txt
├── LICENSE
└── README.md
- Data Cleaning — fixed
TotalChargestype coercion, handled nulls for zero-tenure customers, dropped the ID column. - EDA — churn distribution, churn by contract/payment method, tenure & monthly charges vs. churn, correlation heatmap.
- Feature Engineering — tenure buckets, average monthly spend, total active services, a protection-services flag.
- Encoding & Scaling — one-hot encoding for categoricals,
StandardScalerfor numeric features (used only where the model benefits, e.g. Logistic Regression). - Modeling — Logistic Regression, Decision Tree, Random Forest, XGBoost, LightGBM.
- Evaluation — 5-fold stratified CV, confusion matrix, precision/recall/F1, ROC-AUC and ROC curve, feature importance.
- Deployment — best model serialized with
jobliband served through a Streamlit form.
pip install -r requirements.txtOpen notebook/Customer_Churn_Prediction.ipynb and run all cells. This reproduces the full analysis and writes the trained model artifacts to models/.
cd app
streamlit run app.pyFill in a customer's details and get:
- Churn Probability (e.g.
82%) - Prediction:
HIGH RISK/LOW RISK, with a suggested action
Swap in your own CSV at data/telco_churn.csv — if the column names differ, only the feature-engineering and encoding cells in the notebook need adjusting; the modeling and evaluation sections work unchanged.
Python · pandas · NumPy · scikit-learn · XGBoost · LightGBM · matplotlib / seaborn · Streamlit
MIT — see LICENSE.