A telecom company loses revenue every time a customer cancels their subscription. This project builds a machine learning pipeline to identify customers at high risk of churning before they leave — giving the retention team time to intervene.
| Model | Test AUC | CV AUC (5-fold) |
|---|---|---|
| Logistic Regression | 0.764 | 0.771 ± 0.014 |
| Random Forest ✅ | 0.768 | 0.762 ± 0.021 |
| Gradient Boosting | 0.767 | 0.758 ± 0.015 |
Selected model: Random Forest — best test AUC, robust to outliers, no feature scaling required, and fast to retrain on new data.
- Contract type is the strongest predictor — month-to-month customers churn at 44% vs 10–15% for annual/bi-annual contracts
- New customers are highest risk — churn rate drops significantly after the first 12 months
- Fiber optic customers churn more — likely driven by higher monthly charges and price sensitivity
- Recommended decision threshold: 0.35 (vs default 0.5) — catches ~65% of churners at an acceptable false-positive rate for a low-cost retention campaign (e.g. a discount email)
├── Customer_Churn_Prediction.ipynb # Full notebook — EDA, modelling, evaluation
├── customer_churn_realistic.csv # Dataset (5,880 customers, 20 features)
└── README.md
| Section | What's covered |
|---|---|
| 1. Data Inspection | Shape, dtypes, missing values, class distribution |
| 2. EDA | 6 charts testing hypotheses about churn drivers |
| 3. Preprocessing | Encoding strategy, feature engineering, train/test split |
| 4. Modelling | Logistic Regression, Random Forest, Gradient Boosting |
| 5. Evaluation | ROC-AUC, confusion matrix, cross-validation |
| 6. Feature Importance | Top predictors from both tree-based models |
| 7. Business Recommendations | Threshold tuning, retention strategy, monitoring plan |
Two features were engineered beyond the raw columns:
tenure_group— bucketed tenure into 4 bands (0–12, 12–24, 24–48, 48–72 months) to capture non-linear early churn riskcharge_ratio— monthly charges divided by tenure, capturing average spend rate and the tenure-charge interaction more cleanly than either feature alone
- Python 3 — pandas, numpy, matplotlib, seaborn
- scikit-learn — preprocessing, modelling, cross-validation, evaluation
git clone https://github.com/Tinyiko_Mathebula/customer-churn-prediction
cd customer-churn-prediction
pip install pandas numpy matplotlib seaborn scikit-learn
jupyter notebook Customer_Churn_Prediction.ipynbAt a threshold of 0.35, the model flags approximately 1 in 3 customers as churn risk. For a retention campaign costing $5 per outreach and saving $200 in average customer lifetime value, the model generates positive ROI if it identifies churners with precision above ~2.5% — well within its demonstrated performance.
Tinyiko Patience Mathebula