Projects / Machine Learning

Telco Customer Churn: Analysis & Prediction

Exploratory analysis of telecom customer churn followed by classification models tuned for catching churners. A tuned LightGBM model was chosen for its recall at a 0.45 decision threshold. No business impact was measured.

  • Python
  • scikit-learn
  • LightGBM
  • XGBoost
  • SHAP
Customer records
7,043
Recall (tuned LightGBM)
0.810at threshold 0.45
PR-AUC
0.666as reported; see limitations

Visual evidence

Select any image to enlarge. Use the arrow keys to move between images.

Dataset
Telco customer churn dataset (public)
Size
7,043 customer records, 21 features, plus derived features
Source
Public Telco churn dataset

Business problem

Losing customers costs a telecom more than keeping them. The question was which customers are most likely to leave, which factors are associated with leaving, and whether a model could flag at-risk customers for a retention team.

Dataset

The data has 7,043 customer records with demographics, contract type, internet service, payment method, tenure and charges. Derived features such as AvgChargePerMonth and TenureGroup were added.

Limitations:

  • The data carries tenure but no calendar dates, so it cannot show how churn changes over time.
  • It has no cost or revenue-per-customer information for a retention campaign, so the model cannot be tied to money.
  • Churners are a minority class, which affects how the model must be evaluated.

Analytical workflow

  1. Preparation. Encoding of categorical variables, handling of missing values and outliers, feature sets for linear and tree-based models.
  2. Exploratory analysis. Churn compared across tenure, gender, contract, internet service, payment method and charges.
  3. Diagnostics. Statistical checks on data quality and model readiness.
  4. Modelling. Logistic Regression, KNN, Random Forest, XGBoost and LightGBM compared.
  5. Tuning. A broad RandomizedSearchCV followed by a narrower GridSearchCV, optimising PR-AUC and recall.
  6. Explanation. Tree-based feature importance and SHAP, plus threshold analysis.

Business insights

The exploratory work points to higher churn among short-tenure customers, senior citizens, customers on month-to-month contracts and customers paying by electronic check. Model explanations point to the same area: two-year contract, tenure, fiber optic service, monthly charges, one-year contract and electronic check were among the strongest drivers.

What a retention team could consider (not tested): focus outreach on month-to-month and fiber optic customers, encourage longer contracts and automatic payment, and tailor offers to new and senior customers.

Methodology and technical decisions

  • PR-AUC and recall, not accuracy. With a minority churn class, accuracy rewards predicting “no churn” for everyone. PR-AUC measures the precision-recall trade-off, and recall measures how many real churners are caught.
  • Different feature sets for different models. Linear models and tree models were given suitable inputs; TotalCharges and AvgChargePerMonth were left out of the regression feature set, while tree-based models used TotalCharges.
  • Choosing the model. Tuned XGBoost and tuned LightGBM score almost the same on PR-AUC. LightGBM was preferred because it caught more churners: recall 0.810 compared with 0.532 for XGBoost, and 0.775 for Random Forest.
  • Threshold of 0.45. Chosen from threshold analysis to balance precision and recall. A different threshold would change recall.

Results and limitations

  • Reported for tuned LightGBM: recall 0.810 and PR-AUC 0.666 (from the repository README).
  • A discrepancy to be aware of. The tuned precision-recall chart in the repository labels LightGBM at 0.660 and XGBoost at 0.666. The two models are effectively tied on PR-AUC, which is why the choice rests on recall at the chosen threshold. The exact PR-AUC figure should be checked against the notebook.
  • Higher recall means more false alarms. Precision at the 0.45 threshold is not reported on this page, and the cost of a false alarm is unknown.
  • Feature importance describes what the model uses, not what causes churn.
  • No business impact was measured. The model was not deployed, and no retention campaign was run.

Disclaimer. Personal portfolio project on a public dataset. The model was never deployed and no retention result was measured.

Interested in work like this?

Tell me about your data and the decision you need to make.

Send me a message

Choose how you'd like to email mostafiz.r.afraim@gmail.com