Skip to content
Published: 2026-12-02 · Updated: 2026-12-02 · mltreelib v0.4.21

Customer Churn Prediction: Who Leaves, and When? One Curve per Risk Group

Customer churn prediction usually means three classifiers: will this customer leave within 30, 60 or 90 days? Each one is fitted on its own, so their answers need not agree. On a real retailer's customers, the three probabilities fail to rise with the horizon for 18.4% (sd 7.6 points over 20 seeds) of held-out customers. A customer cannot be less likely to have left by day 90 than by day 30.

The alternative here is two stages: a small risk tree, then one survival curve per leaf. The honest result is that it ties a single survival tree on accuracy. What it adds is one coherent curve for every risk group, including the long tail after day 90. All results are associations in past data, not causes.

Companion post: Customer segmentation: which RFM segments hold up builds segments first and attaches the same kind of curves.

What do three separate churn classifiers get wrong?

They can contradict each other, and they stop at day 90. Three classifiers give a probability at 30, 60 and 90 days, with no 180-day answer and no curve to score. For 18.4% of held-out customers (sd 7.6 points over seeds) the three probabilities do not rise with the horizon. A survival curve cannot do this by construction. Their ranking quality is on par with the alternatives: C-index 0.7354, against 0.7392 for a survival tree (Table 2).

How is churn defined here?

A customer churns after 90 consecutive days without a purchase, and the 90-day clock starts at the snapshot for everyone. The data is UCI Online Retail II (CC BY 4.0): 1,067,371 invoice lines, 2009-12-01 to 2011-12-09. The snapshot is 2011-03-01 and the population is every customer with a purchase in the 365 days up to it, 4,276 customers. Cancellations, non-positive quantities and prices, and lines with no customer ID (243,007 lines) are dropped from purchases. Nothing is imputed.

Exactly: the walk is the snapshot day followed by the customer's later purchases. Duration is the days from the snapshot to the last purchase before the first 90-day gap, and 0 if there is no purchase within 90 days of the snapshot. If no gap is observed before the data end, the customer is censored at 193 days (data end, minus 90, minus the snapshot). Since every censored customer is censored at the same 193 days, "churned by day h" is exactly observed for h up to 180.

Why the snapshot, not the last purchase? An earlier version started each customer's clock at their last purchase before the snapshot. With a 12-month population, about 83% of customers then "churned at day 0" (anyone quiet for 90 days at the snapshot), and recency alone gave the answer. Starting at the snapshot keeps the question open for everyone.

The result: 3,786 customers churn (88.5%), 490 are censored (11.5%), and 2,710 (63.4%) have duration 0. The share whose life ended within 30, 60, 90, 120 and 180 days is 69.8, 75.4, 82.4, 85.2 and 88.3%. This is a high-churn, mostly one-off-buyer population, so absolute numbers will differ in a subscription business.

What is the two-stage design?

Stage one is a shallow risk tree. Stage two keeps its splits and replaces each leaf with a Kaplan-Meier survival curve through tree.retrain(..., leaf_family="survival"). One model then answers "how likely by day 30, 60 or 90" and "what happens after day 90". Trees are depth 3 with at least 100 rows per leaf and no pruning. Features look back from the snapshot only. Stage one comes in two designs.

  • Design B (90-day risk tree): a ModelTree on "churned within 90 days" (binary, mean leaf), then a survival curve per leaf.
  • Design A (four-class timing tree): a softmax ModelTree on the class of when life ended (0-30, 31-60, 61-90, more than 90 days), then a survival curve per leaf. A-ordinal regresses the duration capped at 180 days instead, which keeps the order of the classes that the multiclass tree ignores.

The classes hold 69.8, 5.6, 7.0 and 17.6% of customers. The three stage-one targets pick almost the same splits (active days, recency, frequency, tenure); the retrained curves wash out most differences.

tree = ModelTree(max_depth=3, min_rows=100, prune="none", leaf="mean",
                 leaf_family="binomial", gain="deviance")
tree.fit(features, churned_within_90_days, col_names=names)
tree.retrain(features, (duration, event), leaf_family="survival")

Check: after retrain, each leaf's S(90) equals the empirical share not churned among its rows, with a maximum difference of 3e-16, with and without honesty.

Which customers are at risk, and what do their rules say?

The risk tree gives eight rules a marketing manager can read, an explainable AI summary in business terms. The table is Design B on seed 0, held-out customers, with S(h) the predicted share still active at day h.

Leaf Rule Stage-1 risk n test S(30) S(90) S(180) Observed churned <=90
6 frequency > 10 AND active_days > 5 AND recency_days <= 15 0.091 43 0.945 0.909 0.827 0.116
7 recency_days > 15 AND frequency > 10 AND active_days > 5 0.307 48 0.802 0.693 0.584 0.312
5 active_days > 5 AND avg_basket_items > 196 AND frequency <= 10 0.461 52 0.708 0.539 0.351 0.481
2 2 < active_days <= 5 AND recency_days <= 26 0.672 62 0.496 0.328 0.191 0.613
4 active_days > 5 AND frequency <= 10 AND avg_basket_items <= 196 0.684 84 0.540 0.316 0.219 0.667
0 active_days <= 2 AND tenure_days <= 74 0.829 64 0.264 0.171 0.071 0.891
3 recency_days > 26 AND 2 < active_days <= 5 0.858 276 0.313 0.142 0.077 0.841
1 tenure_days > 74 AND active_days <= 2 0.965 654 0.126 0.035 0.012 0.956

Stage-1 risk is the tree's estimated probability of churn within 90 days; the last column is what held-out customers did. The leaf curves are plotted below.

Survival curves for each leaf of the 90-day risk tree

What does the 90-day number hide?

A lot, in the low-risk leaves. Leaf 6 has S(90) of 0.909, yet only 91.0% of its customers still active at day 90 are still active at day 180. In leaf 7 the figures are 0.693 and 84.3%. A 90-day probability alone would call both leaves safe; the curve shows that roughly 1 in 11 and 1 in 6 of those who looked safe at day 90 are gone by day 180. Of the customers still active at day 90, 97.0% (leaf 6) and 90.0% (leaf 7) are still active at day 120. Held-out customers in leaf 6 churned by day 180 at 20.9%, and in leaf 7 at 43.8%.

Does two-stage beat a single survival tree?

No. It ties it on accuracy. Table 2 gives held-out results, mean ± sd over 20 seeds. C-index is Harrell's concordance (higher is better). IBS is the integrated Brier score over days 1 to 180 (lower is better). Calibration error is the share-weighted mean absolute gap between predicted and observed churn, per group of equal prediction (lower is better).

Table 2. Held-out results, mean ± sd over 20 seeds (main snapshot).

Method Leaves C-index IBS (days 1-180) Cal. err. 90d Cal. err. 180d
B: binary 90-day risk, no honesty 7.6 0.7361 ± 0.0133 0.1135 ± 0.0043 0.0252 0.0197
B, honesty flag 6.0 0.7306 ± 0.0123 0.1152 ± 0.0045 0.0234 0.0180
B, split sample 6.0 0.7319 ± 0.0146 0.1160 ± 0.0048 0.0276 0.0207
A: four-class timing, no honesty 7.8 0.7398 ± 0.0128 0.1129 ± 0.0046 0.0269 0.0210
A, honesty flag 6.0 0.7356 ± 0.0114 0.1147 ± 0.0046 0.0228 0.0173
A, split sample 5.9 0.7369 ± 0.0146 0.1154 ± 0.0046 0.0258 0.0210
A-ordinal: capped duration, no honesty 7.5 0.7385 ± 0.0129 0.1134 ± 0.0044 0.0256 0.0214
A-ordinal, honesty flag 5.5 0.7319 ± 0.0108 0.1151 ± 0.0047 0.0196 0.0174
A-ordinal, split sample 5.8 0.7337 ± 0.0153 0.1155 ± 0.0048 0.0261 0.0196
Three classifiers (30/60/90) 3 x 8 0.7354 ± 0.0129 n/a 0.0252 n/a
Single-stage survival tree (log-rank) n/a 0.7392 ± 0.0127 0.1133 ± 0.0047 0.0245 0.0209
One Kaplan-Meier curve n/a 0.5000 ± 0.0000 0.1557 ± 0.0046 0.0100 0.0092

Every two-stage variant without honesty lands between 0.736 and 0.740 on C-index and 0.1129 to 0.1135 on IBS, against 0.7392 and 0.1133 for the single tree. The multiclass design A has the best mean C-index and IBS, but its margin is within one standard deviation across seeds (no paired test was run between A and the baseline). The classifiers have no 180-day answer and no IBS. One curve for everybody looks best on calibration only because it is one group.

So the value of two stages is not accuracy over a survival tree. It is one model that gives the whole curve, from the 30, 60, 90 day view to the long tail; coherence across horizons by construction; and a readable risk-first split.

Does honesty (split-sample estimation) help?

It adds at most a small calibration gain and costs ranking and Brier accuracy. Honesty means choosing the splits on one half of the customers and estimating the leaf curves on data the splits did not see, either with ModelTree(honesty=True, honesty_fraction=0.5) or by fitting the tree on one half and retraining on the other. Paired by seed, against no honesty (variant minus none):

Variant IBS change Seeds with better IBS 90-day calibration change Seeds with better calibration C-index change
B, flag +0.0017 3/20 -0.0018 11/20 -0.0055
B, split +0.0025 2/20 +0.0024 8/20 -0.0042
A, flag +0.0018 2/20 -0.0041 16/20 -0.0042
A, split +0.0025 1/20 -0.0011 11/20 -0.0030
A-ordinal, flag +0.0017 4/20 -0.0061 16/20 -0.0066
A-ordinal, split +0.0020 1/20 +0.0005 9/20 -0.0048

Honesty worsens IBS by 0.0017 to 0.0025 (worse in 16 to 19 of 20 seeds in every case) and C-index by 0.003 to 0.007. Calibration at 90 days improves with the flag for the multiclass and ordinal trees (16 of 20 seeds, by 0.004 and 0.006) and is a coin flip for the binary tree (11 of 20). The split-sample version is no better than none on calibration (8 to 11 of 20), because its leaf curves rest on half the customers. Honest trees are also smaller, about 6 leaves against 7.6.

In this data (about 3,000 training customers, strong signal) honesty is a small calibration gain at best, paid for in discrimination. It is not a win here. It does show why honest estimates exist: in seed 0, the honest leaf "active_days > 5 AND recency_days <= 43" had a stage-one churn estimate of 0.256 on the structure half, retrained survival says 0.384 churned by day 90, and held-out customers did 0.294. The structure-half estimate was optimistic; the estimation-half one was noisy.

Which churn prediction model should you use?

  • Only the best ranking or calibration: a single survival tree is as good (C-index 0.7392, IBS 0.1133). It is the simplest model.
  • One coherent answer per risk group, from day 30 to the long tail, with readable rules: the two-stage design (B or A). Pick B if the business question is "who is at risk in 90 days", A if the timing classes matter.
  • Honesty: consider it only if you need leaf estimates that are not tuned to the same customers as the splits, and accept the loss in IBS and C.
  • Retire three separate classifiers when probabilities must be consistent across horizons.

What are the limits?

  • One retailer, one main snapshot day, one 90-day churn rule, a mostly one-off-buyer population. Rerun on your own data before relying on a number.
  • 63.4% have duration 0, so most of the signal is "who buys again at all". Leaves with few test customers (43 to 64) give noisy curves.
  • These are associations in past data. A high-risk leaf is not evidence that a retention offer would change the outcome; that takes a randomised holdout.
  • Other observations from the experiments: extract_rules() on a survival tree prints THEN prediction = 0.0000 for every leaf (the conditions are right), and a regression ModelTree defaults to a linear leaf, so stage one sets leaf="mean".

How do I reproduce it?

uv run --with openpyxl --with matplotlib python examples/guides/churn_risk_timing.py

The script downloads UCI Online Retail II once through mltreelib.datasets.load_online_retail_ii (rows returned unchanged, pinned SHA-256). Matplotlib only draws the figure. Cleaning, snapshot, features and the churn rule are in examples/guides/retail_snapshot.py, shared with the segmentation post (examples/guides/two_stage_survival.py). The unedited output is in references/research/2026-12-02-churn-segmentation-experiments.md. Source: churn_risk_timing.py.

Next: Customer segmentation: which RFM segments hold up, and when do they churn.