Production Pipeline for Predicting Subscriber Cancellation Within a Week
Machine LearningModel answerLast updated
Design, evaluate, monitor and roll out a weekly-horizon churn model on a shaky data foundation, covering leakage, time-aware validation, drift detection, retraining rules and fairness.
You take over a model that estimates, for each user, the probability of leaving within the next 7 days. Its input data is unreliable, and the team suspects that feature distributions have shifted over time. You are asked to put the system on solid footing. Answer each part below.
Part 1: Pipeline design
- How do you split time into a feature window and a label window?
- Which controls keep information from after the prediction moment out of training data?
- Which validation scheme suits time-ordered data?
- How do you make sure features computed for training match the ones used at serving time?
Part 2: Metrics and decision threshold
- Which offline metrics do you track (for example ROC-AUC, PR-AUC, calibration error)?
- Which business metrics show whether targeted interventions actually improve retention?
- How do you pick a score cutoff when a missed churner and a wasted intervention have different costs?
Part 3: Monitoring
- Describe concrete checks for missingness, schema, and training-serving skew.
- Describe feature drift detection using PSI or JS divergence, with alert levels (for instance, PSI above 0.25 is severe).
- Explain how you would tell a change in input distributions apart from a change in the target caused by a product update.
Part 4: Deployment and lifecycle
- Lay out a rollout using shadow scoring, a canary, live monitoring, and rollback conditions.
- Define explicit retraining triggers (for example, a scheduled weekly retrain when PSI stays at a moderate level two weeks running, or when a business KPI falls by X%).
- Explain how you would check fairness across at least two sensitive cohorts and what you would do about any gaps found.
State your assumptions (user volume, base rate, intervention capacity) and discuss trade-offs.
Hints
Hint 1
Anchor everything to a prediction timestamp t: features may use only data that had actually arrived before t (think ingestion time, not just event time), and labels come from the 7 days after t. Then ask what a validation split must do so that no label window overlaps a training feature window.
Hint 2
For thresholding, write the expected value of treating one user as probability of churn times the chance the treatment saves them times the value of a saved user, minus the treatment cost. Treat when that is positive, and remember that capacity limits and a randomized holdout group change how you apply and verify the cutoff.
Hint 3
For drift, separate three questions: did the inputs move, did the base rate move, or did the relationship between inputs and outcome move? Matured labels, calibration by score bin, and the release/experiment calendar each help answer a different one. Also weight alerts by feature importance so you page on what matters.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions
- About 10M active users, scored in a daily batch at a fixed cutoff
t(for example 00:00 UTC); an optional low-latency endpoint for in-session triggers. - "Churn" means no qualifying activity in
(t, t+7d]for a user active in the prior 30 days. The definition of "qualifying activity" is versioned, since product changes can silently alter it. - Base rate around 5%, so the problem is imbalanced. Interventions (email, discount) are capacity-limited, say 50k per day.
Part 1: Pipeline design
Temporal slicing. For each snapshot t, features come from [t - W, t) for several W (7, 30, 90 days) to capture recency, frequency and trend. The label comes from (t, t+7d]. Training data is many weekly snapshots stacked, one row per (user, t).
Leakage controls
- Point-in-time joins on availability time (
ingest_ts <= t), not justevent_ts <= t, so late-arriving events cannot leak in. - Fit scalers, encoders, imputers and target encodings inside each training fold only.
- Remove proxies generated by the churn process itself (cancellation-page visits or support tickets after
t). - Sanity test: shift features back a day and compare. A suspiciously large dependence on same-day features signals leakage.
Validation. Use rolling-origin (forward-chaining) splits with an embargo of at least 7 days between the end of training and the validation start, because the last training label windows overlap validation feature windows. Run 6-8 folds and keep the most recent ~4 weeks as an untouched holdout. Random K-fold is a common mistake: it lets the future inform the past and inflates metrics.
Training/serving consistency. Define each feature once, version it, and generate both stores from the same transformation code. The offline store supports point-in-time retrieval; the online store is materialized from the same logic. Log the exact feature vector at inference and train on logged features where possible, which removes skew by construction. Each model artifact in the registry pins its feature-set version.
Part 2: Metrics and threshold
Offline. PR-AUC is primary given 5% prevalence; ROC-AUC is a ranking sanity check; precision/recall at k match the capacity limit; Brier score and ECE measure calibration (alert if ECE > ~0.05). Calibrate with isotonic or Platt scaling on a later time fold, since the threshold step uses probabilities directly.
Business. Keep a persistent randomized control (for example 10% of high-score users never treated) to measure incremental retention. Report net value per 1,000 treated: saves x value per retained user minus intervention cost. High AUC does not imply uplift, since the model may rank users who would churn regardless of treatment.
Cost-sensitive cutoff. Let V be the value of a retained user, u the save rate of treatment among true churners, C the cost per treatment (including discount leakage and annoyance on non-churners). Treat when p * u * V > C, so p* = C / (u * V). With generic misclassification costs, p* = C_FP / (C_FP + C_FN). If capacity binds, take the top k among users above p*. Estimate the cutoff on validation folds with bootstrap intervals, and re-derive it as u is re-estimated from the control group. The mature end state is an uplift model ranking by the difference in save probability with and without treatment.
Part 3: Monitoring
| Monitor | Method | Alert |
|---|---|---|
| Schema | Types, enums, ranges, required columns | Hard fail, block scoring |
| Volume/freshness | Rows vs trailing 7-day mean; ingest lag | +/-20% rows; lag > 6h |
| Missingness | Null rate vs training baseline | +5pp or > 3 sigma |
| Train-serve skew | Recompute offline features for sampled served (user, ts) and compare to logged | > 1% mismatch |
| Numeric drift | PSI on training-decile bins | 0.1-0.25 moderate, > 0.25 severe |
| Categorical drift | JS divergence | > 0.1 warn, > 0.2 severe |
| Prediction drift | PSI of scores, share above threshold | PSI > 0.25 or flagged rate +/-50% |
Weight alerts by feature importance: PSI 0.3 on a feature with negligible SHAP is a ticket, not a page.
Separating covariate drift from target drift. Labels arrive with a 7-day lag; once matured:
- Covariate shift: feature PSI is high, but calibration within score bins still holds.
- Prior (base-rate) shift: the churn rate moves but conditional relationships hold. Recalibrating the intercept may suffice.
- Concept drift: calibration curves or PR-AUC degrade even where inputs are stable. Retrain.
- Product attribution: overlay the release and experiment calendar; compare control and treatment arms of an experiment. If only the treated arm shifted, the product change is the cause. If a release redefined "activity," that is a label-definition change: version the label rather than training on a corrupted target.
Part 4: Rollout and lifecycle
- Shadow (about 2 weeks). The challenger scores everyone without acting. Compare latency, skew, score distribution and rank overlap with the champion; after labels mature, compare PR-AUC and ECE.
- Canary. Move 5%, 25%, 50%, 100% of decisions to the challenger, holding each stage for at least one label cycle.
- Live monitoring. Track latency, error rate, feature null rates, score distribution and flagged-rate in real time; track retention lift and net value once labels mature.
- Rollback triggers. Schema or skew failure, score PSI > 0.25, p99 latency or error budget breach, or a canary KPI drop beyond a pre-set tolerance (for example a statistically significant retention-lift loss versus the champion). Rollback is a registry pointer flip to the previous model and feature version.
Retraining triggers. Retrain on a weekly or biweekly schedule by default, plus event-driven: (a) moderate PSI (0.1-0.25) on important features for two consecutive weeks, (b) any severe PSI on a top feature, (c) PR-AUC or lift down by more than X% (say 10% relative) versus the validation baseline, or (d) ECE above tolerance after recalibration fails. A retrain only ships if it beats the champion on the time-forward holdout and passes shadow.
Fairness. Pick at least two cohorts (for example age band and region or device type, subject to legal availability of the attributes). Compare selection rate, recall (true-positive rate), false-positive rate, and calibration per cohort, plus differences in treatment benefit. Flag gaps beyond a tolerance (for example a ratio outside 0.8-1.25). Mitigations: check data coverage and label quality for the cohort, add features or reweight, use per-cohort thresholds or calibration if policy allows, and constrain training. Always weigh the trade-off against overall value and re-measure after changes. Note that withholding an intervention can itself harm a group, so look at who receives the benefit, not only who is flagged.
Common mistakes
- Random splits and no embargo.
- Joining on event time instead of availability time.
- Optimizing AUC and ignoring calibration and uplift.
- Alerting on every drifting feature regardless of importance.
- Retraining on a corrupted target after a label-definition change.