Customer retention intelligence · portfolio project

Know who is about to leave before they do.

A reproducible churn model and retention workbench built on 7,043 IBM Telco customers. It turns a probability ranking into an explicit contact policy — with the evaluation, trade-offs, and limits on the table.

Live client-side scorer · logistic regression · 0.846 holdout ROC-AUC · threshold tuned out-of-fold · one-time holdout evaluation

Holdout signal / 1,409 accounts Model live

Cumulative churn captured

66.0%

in the top three risk deciles — 247 of 374 holdout churners.

Top 10% of accounts28.6%
Top 20% of accounts50.3%
Top 30% of accounts66.0%
0.846ROC-AUC
72.2%Recall
54.9%Precision
Dataset
7,043
customers · 21 raw columns
Observed churn
26.5%
1,869 churners in the historical base
Annualised churn revenue
$1.67M
observed monthly charges from churned accounts × 12
Holdout ROC-AUC
0.846
72.2% recall · 54.9% precision at 0.583

01The signal

Churn is concentrated,
not random.

Three observable account facts carry most of the signal — and most of the revenue exposure. The model is most useful when it ranks the next-best accounts inside those segments, not when it treats every customer as equally urgent.

01
Contract 42.7%

Month-to-month accounts churn at roughly four times the two-year rate.

Versus 11.3% on one-year and 2.8% on two-year contracts. Commitment length is the strongest segment signal in the data.

55.0% of customers88.5% of churners
02
Tenure 52.9%

The first six months carry the highest churn rate in the lifecycle.

Risk falls sharply after the first year and reaches 6.6% in the 61–72 month cohort. Onboarding is a retention window, not a footnote.

1,481 customers$599K annualised churn revenue
03
The actionable overlap 54.6%

Month-to-month fiber is where risk and revenue exposure compound.

The highest-risk large segment — and the clearest campaign target. This is the pool where a focused retention motion has the most leverage.

30.2% of customers62.2% of churners72.2% of churn revenue
Horizontal bar charts showing churn rate by contract, internet service, and payment method. Month-to-month, fiber optic, and electronic check are highest.
FIG. 01 Three dimensions, one pattern. Churn concentrates in short-commitment, higher-price, self-service accounts. Source: 7,043 records with observed churn labels.

The actionable overlap

30.2% of customers. 62.2% of churners. 72.2% of the revenue exposure.

Month-to-month fiber accounts are not a niche. They are a large, measurable pool where a focused retention motion has the most leverage. The model's ranking decides which accounts inside that pool a team works first.

Share of customers30.2%
Share of churners62.2%
Share of annualised churn revenue72.2%
Churn overview showing a donut chart of retained versus churned customers, churn rate by contract length, and churn rate by tenure band.
FIG. 02 The lifecycle amplifies the segment effect. The first six months are the highest-risk stage; the 61–72 month cohort is down to 6.6% churn.

02The workbench

A score is not a strategy.
This is the workbench around it.

The Streamlit app turns the model into five linked surfaces: an executive overview, a single-customer scenario workbench, batch scoring, a threshold sandbox, and the method notes. The public browser scorer is the same fitted model exported to JavaScript; the Streamlit pages remain the full native reference.

01

Interrogate a single score

Change tenure, contract, services, and billing facts. The score, risk tier, revenue at risk, drivers, and retention plays update together.

02

Work a list, not a demo

Upload the raw Telco schema, validate every row, score the portfolio, and download a ranked campaign file.

03

Make the policy explicit

Move the threshold and watch precision, recall, contact volume, and decile capture change against saved holdout predictions.

04

Put the limits in the product

A model card, data dictionary, and reproduction steps live beside the scores — not in a footnote.

Try the model before you read the rest.
Single accounts, threshold lab, and CSV batch scoring — no login, no server.

Open the scorer
localhost:8501 · customer risk scorer
Customer risk scorer page with account inputs, an 88.1% churn probability, a critical risk tier, revenue at risk, and a gauge.
01 / Customer risk scorerOne-at-a-time sensitivity against training baselines — transparent, and explicitly not causal.
localhost:8501 · batch scoring
Batch scoring page with a CSV upload, a 25-row sample, customer-level probabilities, risk tiers, and a downloadable scored file.
02 / Batch scoringValidate a raw customer file, score it in one pass, and export the ranked list with revenue-at-risk estimates.

03Evaluation

Every number is regenerated,
not hand-typed.

Five candidate pipelines are compared with 5-fold stratified CV ROC-AUC. The winner is evaluated once on a 20% holdout; the decision threshold is tuned on out-of-fold training predictions, not on the test set.

CV ROC-AUC
0.8474
± 0.0110 · 5-fold stratified
Holdout ROC-AUC
0.8457
1,409 customers · 374 churners
Recall
72.2%
270 of 374 churners flagged
Precision
54.9%
270 of 492 contacts were churners

PR-AUC 0.6532 · F1 0.6236 · Brier 0.1657 · top-decile lift 2.86× · top three deciles capture 66.0% of holdout churners.

Grouped horizontal bar chart comparing 5-fold cross-validation and holdout ROC-AUC for five candidate models. Logistic regression is highest.
FIG. 03 Five candidates, one rule. Selection is by CV ROC-AUC, not by a hand-picked holdout result. Error bars show CV variability.
Confusion matrix at threshold 0.583: 813 true negatives, 222 false positives, 104 false negatives, and 270 true positives.
FIG. 04 Holdout confusion matrix at the deployed 0.583 threshold.

Why logistic regression?

The simplest model won the selection rule.

It beat gradient boosting on CV ROC-AUC (0.8474 vs 0.8456), is easier to explain and monitor, and serializes to a 6.6 KB bundle. The extra complexity did not buy better holdout ranking.

  • Preprocessing lives inside the pipeline, so CV refits the encoder in every fold.
  • The threshold is selected on out-of-fold training predictions.
  • The holdout set is scored once, after model selection.
  • The winning pipeline is refit on all labelled rows only for deployment.

Decision policy

0.583 is a capacity decision, not a default.

At the deployed threshold, 492 of 1,409 holdout accounts are flagged. The model catches 270 churners and contacts 222 retained customers. A lower threshold catches more churn; a higher one protects outreach capacity.

270churners caught
104churners missed
222retained customers contacted
34.9%alert rate
Risk distribution charts showing customers and observed churn rate by Low, Medium, High, and Critical risk tiers on the holdout set.
FIG. 05 The risk bands separate churners from retained customers. The top three probability deciles capture 66.0% of all holdout churners — the practical case for a limited outreach team.

Permutation importance

What the model leans on

The top five features account for 86.5% of the measured holdout importance. Correlated features can share credit.

Tenure 21.2% Internet service 19.5% Contract 18.9% Monthly charges 18.4% New customer 8.4%

04Method

Reproducible by design.
Honest by default.

A deterministic CLI takes the raw CSV to a serialized bundle, evaluation tables, and generated figures. The app reads those artifacts; it never retrains on page load.

  1. 01

    Validate the schema

    Check required columns, unique customer IDs, numeric tenure and charges, and valid target labels.

  2. 02

    Engineer features

    Handle 11 blank TotalCharges records explicitly; add AvgMonthlySpend, ServiceCount, and IsNewCustomer.

  3. 03

    Compare five candidates

    Logistic regression, random forest, gradient boosting, histogram gradient boosting, and extra trees under 5-fold stratified CV.

  4. 04

    Tune the decision

    Select the model by CV ROC-AUC. Tune the F1 threshold on out-of-fold training predictions, not on the holdout.

  5. 05

    Evaluate once, then export

    Score the 20% holdout, refit the winner on all labelled rows, and serialize the model, threshold, baselines, and metadata.

From clone to score
# clone and install
git clone https://github.com/mlaharsh/Customer_Churn_Prediction.git
cd Customer_Churn_Prediction
python -m venv .venv

# Windows
.venv\Scripts\activate
# macOS / Linux
# source .venv/bin/activate

pip install -r requirements-dev.txt
python -m churn.train
python -m pytest -q
streamlit run app.py
11 blank charges, handled explicitly All at tenure = 0. Filled as MonthlyCharges × tenure, which is zero for those records.
22 model features Three deterministic derived features. One-hot encoding and scaling live inside the pipeline.
One holdout, one decision Stratified 20% split. No repeated peeking at test performance while tuning.

05Limits & responsible use

What this model
cannot prove.

A useful model is honest about its boundary. This is a retrospective risk-ranking exercise, not a causal uplift study, a production credit system, or a guarantee of customer behavior.

01 / VALIDATION

Retrospective, not temporal

One historical 80/20 split. There is no time-based validation or live experiment, and the historical Telco base may not represent a current customer population.

02 / CAUSATION

Correlation, not causation

The what-if view resets one feature at a time. It can tell you which account facts are associated with risk, but not what a retention offer will change.

03 / CALIBRATION

Probabilities are not exact odds

The Brier score is 0.1657. Scores are useful for ranking and campaign sizing; they should not be read as an individual's exact probability of leaving.

04 / FAIRNESS & DRIFT

The monitoring burden is real

Gender and senior-citizen status are in the schema. Subgroup performance, score drift, alert rate, and realized churn require ongoing review before operational use.

If this went to production

Validate the decision,
not just the score.

The model is a starting point for a measured retention program, not a finished policy.

  1. Run a temporal holdout and a live A/B or matched-control test.
  2. Set the threshold from contact capacity and the relative cost of a missed churner.
  3. Measure uplift, not just observed churn among contacted accounts.
  4. Monitor calibration, alert rate, segment drift, and subgroup error rates.

Open source · MIT

Inspect every number.
Run every step.

The model bundle, evaluation tables, tests, Docker image, CI workflows, and the Streamlit workbench are all in the repository. No hidden notebooks, no hand-typed metrics.