← All projects

Which telecom customers are most likely to leave, and why?

Python, pandas, scikit-learn, XGBoost, SHAP · Code and notebooks on GitHub

51% of churners reached by contacting the top 20% of customers by predicted risk

A tuned XGBoost model ranks customers by churn risk with ROC-AUC 0.845. Contacting the riskiest 20% reaches 2.55 times as many churners as contacting a random 20%. Month-to-month contracts, short tenure and fibre-optic internet are the strongest signs a customer will leave.

The data

The public Telco Customer Churn dataset from Kaggle: 7,043 customers, one row each, with 21 columns covering contract, tenure, services, charges and a yes/no churn flag.

Cleaning was mostly type fixes. The 11 blank total-charges values all belonged to customers with zero months of tenure, so they were set to 0 rather than dropped. Before modelling I explored churn by contract, service and payment method, checked associations between categorical features with Cramér's V, and fit a Kaplan-Meier survival curve on tenure.

Choosing a model

I compared three models with stratified 5-fold cross-validation, inside a scikit-learn Pipeline so every model saw the same preprocessing without leakage. XGBoost was tuned with a grid search and early stopping, which lifted it from 0.822 to 0.845 ROC-AUC.

Cross-validated scores, mean ± standard deviation
ModelROC-AUCAverage precisionF1
Logistic regression0.842 ± 0.0130.653 ± 0.0150.594 ± 0.029
Random forest0.823 ± 0.0090.618 ± 0.0230.549 ± 0.033
XGBoost (tuned)0.845 ± 0.0090.660 ± 0.0110.557 ± 0.023

XGBoost won on the two ranking metrics, which is what this use case needs. F1 depends on a single yes/no cut-off, and the point here is to rank customers. Logistic regression is within one standard deviation, so it is the better choice if interpretability matters more than a small gain in ranking.

What drives churn

SHAP values show how much each feature raised or lowered each customer's predicted risk. I summed the one-hot columns back into their original features, so contract type is ranked as one feature rather than three.

Bar chart of grouped SHAP feature importance. Contract type is highest, followed by tenure and internet service.
Contract type, tenure and internet service carry most of the model's signal.
  • Month-to-month customers churn far more than one- or two-year customers, and the tenure effect is strongest on those plans.
  • Churn falls steadily the longer someone has been a customer.
  • Fibre-optic customers churn much more than DSL or no-internet customers, even though fibre is the premium product. Higher monthly charges also raise risk.

Who to contact

Ranking customers on the held-out test set shows how many churners each outreach size would reach.

Customers contactedChurners reachedLift over randomPrecision
Top 10%29.3%2.94x0.778
Top 20%51.0%2.55x0.676
Top 30%67.9%2.26x0.600
Top 40%79.9%2.00x0.530

Based on the drivers, I'd test incentives to move high-risk month-to-month customers onto longer contracts, and look into why fibre customers leave at such a high rate.

Limitations

  • The data has no cost or revenue per customer, so the table above says how many churners each cut-off reaches, not what a campaign would save.
  • The drivers are associations, not causes. Any retention offer would need testing against a held-out control group.
  • The next modelling step is logistic regression with interaction terms, given how close it already is to XGBoost.