Skip to content

How it's builtMachine learning

Churn Predictor

Two models trained in your browser predict which subscribers of Marina Fibre, a broadband provider I made up, will cancel next month: a logistic regression and a decision tree. They learn from 1,875 sample subscribers and are tested on 625 they never see.

The problem

A broadband provider loses some subscribers every month, and winning a new one costs far more than keeping an old one. The retention team can only make so many calls, so the question every week is who to call, and what to say.

A churn model ranks subscribers by risk and gives each a reason. The threshold turns the ranking into a call list, and choosing it is a business decision more than a technical one: a low threshold catches more leavers but spends calls on people who were staying anyway.

The data

2,500 subscribers in four Chennai zones (Central, South, West and OMR), each with tenure, plan speed (40 to 500 Mbps), monthly bill, contract, autopay, support tickets in the last 90 days, outages in the last 30, the change in data use over the last month, late payments in the last six months and the age of the router.

I generated them, and who leaves follows a rule I wrote: short tenure, a monthly contract, no autopay, tickets, outages, falling use and late payments raise the chance; an annual contract and long tenure lower it. Two quirks give the models something to find: outages hurt far more on a monthly contract, and OMR has a new rival. Random noise goes on top, and 18% leave. The models never see the rule.

The split is fixed: 75% to train and 25% to test, picked at random with a seed, so the numbers repeat on every visit.

The model

Logistic regression on standardised columns, with zone and plan one-hot encoded and tenure on a log scale, because the first months are the riskiest. Its weights read directly: how much each column pushes the odds of leaving. A subscriber's reasons are the columns that push their own score up the most, in plain words: "3 tickets in 90 days", "monthly contract".

A decision tree four questions deep, with at least 30 subscribers in every leaf. It ranks a little less well here, but it finds the interaction between outages and the contract without being told, and its rules read like a retention playbook. Its riskiest branch: IF monthly contract AND outages ≥ 1 AND data use change ≤ −14% AND no autopay THEN 65% leave.

The threshold is where the business comes in. A call has a cost, a kept subscriber has a value, and only some of the called leavers stay. The demo works out the expected net value of the call list at every threshold and marks the best one. With sensible numbers it sits well below 50%, the threshold most tools use by default.

The pipeline

  1. 01
    Generate

    2,500 sample subscribers from a fixed seed, the same on every visit.

  2. 02
    Split

    75% to train; 25% held back to test.

  3. 03
    Encode

    Zones and plans one-hot, tenure on a log scale and every column standardised for the regression; raw values for the tree.

  4. 04
    Train

    Both models fit in a fraction of a second, in your browser.

  5. 05
    Score

    Every test subscriber gets a risk from each model; the ROC curve and its area measure how well they rank.

  6. 06
    Decide

    The threshold makes the call list; the cost of a call and the value of a kept subscriber turn it into a net figure.

  7. 07
    Explain

    Reasons from the regression's contributions or the tree's path, and a what-if on the contract and autopay.

Results

Regression AUC
0.830
on 625 test subscribers
Tree AUC
0.777
14 readable rules
At a 50% threshold
39 calls
precision 74%, recall 26%
Best threshold
19%
203 calls, net ₹93,900

Measured when this page was built, with the same code the demo runs. The value figures assume a ₹300 call, ₹6,000 for a year kept and 30% of called leavers staying: the best threshold is worth ₹93,900 on the test subscribers, against ₹40,500 at 50%.

For a client

With a client's data I would start from the billing system, the support desk and network monitoring, which hold most of these columns, then add what matters in their market: a rival's launch in an area, a price rise, a contract about to end.

I would retrain every month and measure the model on the next month's real cancellations. The save rate needs measuring too, with a small group that is not called, so the value of the call list is known rather than assumed.

The scores can land in the CRM as a weekly call list with the reasons beside each name, which is what a retention team actually works from.

Stack

PartWhat it does hereLicence
My machine-learning libraryLogistic regression, the decision tree, the ROC curve, the metrics and the sample generator, written in TypeScript and unit-testedMine
PreactThe interactive demoMIT
AstroThe page, built as static HTMLMIT

Privacy

Everything happens in your browser. The numbers you try and the call list you download never leave your device: there is no server behind this page.

Limits

  • The data is generated, so the accuracy shows how well the models recover the rule I wrote, not how they would do on a real provider's subscribers.
  • The share of called leavers who stay is a guess you type in. In real life it has to be measured.
  • A model trained on last year's leavers can miss a new reason to leave, such as a rival arriving in one area, until it is retrained.
  • Neither model knows anything outside its columns: a rude engineer or a house move is invisible to it.