Predict Which Free-Tier Merchants Will Upgrade to a Paid Plan
Machine LearningModel answerLast updated
Design a production-ready ML pipeline to identify free-tier merchants likely to convert to a paid subscription within 60 days, covering labeling, leakage, features, modeling, evaluation, and monitoring.
Paid Plan Conversion Prediction
A payments platform offers a free tier and a paid subscription tier. The business team wants a scored list of free-tier merchants most likely to upgrade to the paid plan within the next 60 days, so account managers can reach out proactively. You have access to transaction history and merchant metadata up to 2025-07-03, and the target outcome window ends 2025-09-01.
Design a production-ready classification system. Address each part below concisely but precisely.
What to cover
(a) Labeling Define exactly who is eligible for scoring, what counts as a positive, what counts as a negative, and what the observation and outcome windows are. Explain how you handle merchants already on the paid tier and newly created merchants with little history ("cold-start").
(b) Leakage Identify at least five concrete data-leakage risks specific to this problem — not generic ones — and describe how each would be prevented through time-gated feature windows, as-of snapshots, or proper train/validation splits.
(c) Features Propose 15–25 high-signal features computable from transaction history and merchant metadata. Cover recency/frequency/monetary signals, recurring-billing behavioral patterns, customer concentration, payment-method diversity, timing signals, risk indicators, growth rates, and metadata such as account age, vertical, and geography.
(d) Modeling Select two model families and justify the choice. Discuss how to handle severe class imbalance. Describe your calibration strategy and how you would present model output to a non-technical sales team.
(e) Evaluation Specify how you structure time-based cross-validation. Name your primary metrics and explain how you would pick a decision threshold to deliver a ranked list of 1,000 merchants with expected precision ≥ 0.60.
(f) Monitoring Define what you would track after deployment — feature distribution drift, label drift, calibration drift — and explain how you would trigger retraining without letting future labels contaminate the next training run.
Hints
Hint 1
Anchor every feature window strictly to the observation cutoff date. If any computation touches data after that date — even indirectly through a joined table — it is leakage.
Hint 2
Optimizing for PR-AUC during training is not the same as selecting a threshold for deployment. Calibrated probabilities let you pick a threshold by reading precision directly from the precision-recall curve at rank 1,000.
Hint 3
Merchants already on the paid tier are neither positives nor negatives — they belong to a completely different problem. Silently including them as negatives will distort both training and evaluation.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach and Key Decisions
The core discipline this problem tests is temporal correctness: every label, every feature, and every validation fold must respect the direction of time. Establish the timeline first; everything else follows.
(a) Labeling
Windows. Let the observation cutoff be T = 2025-07-03. Features may only use data with event and ingestion timestamps ≤ T — ingestion matters because chargebacks and refunds on pre-T transactions often post weeks after the fact. The outcome window is (T, 2025-09-01], exactly 60 days.
Training snapshots. You have no ground-truth labels at T yet, so you cannot train on T alone. Instead, construct historical snapshots at monthly offsets t₁, t₂, … tₙ where tᵢ + 60 days ≤ T. The latest usable snapshot is 2025-05-04. For each snapshot tᵢ, recompute all features as of tᵢ and assign labels from (tᵢ, tᵢ + 60d].
Eligible population at cutoff t:
- At least one successful charge in the 90 days before t (active merchant).
- No paid-tier activation on or before t — no subscription charge, no billing product flag, no subscription object in live mode.
- Not closed, rejected, or suspended at t.
Already-paid merchants are excluded entirely. They are an upsell or retention problem, not a conversion problem. Treating them as negatives would suppress the model's view of upgrade signals.
Positive: the first live-mode paid-tier activation event falls in (t, t + 60d]. Use the first live-mode recurring charge as the adoption signal, not test-mode objects or trial creations — both create trivial false positives.
Negative: eligible at t with no paid-tier event by t + 60d. Merchants who close during the window remain negatives; document this choice explicitly.
Cold-start merchants (fewer than 28 days of history) have unreliable transactional features. Two reasonable options: train a lightweight parallel model on metadata-only features and flag cold-start merchants separately in the output; or keep them in the main model with a tenure_days feature and explicit missing-value indicators. Report their precision separately, since sales may want a different confidence threshold for them.
(b) Leakage risks
-
Merchant category or product-type fields read from a current-state table. If a merchant is reclassified as "SaaS" after upgrading, that label leaks the outcome. Fix: use slowly-changing-dimension history or point-in-time snapshots; never join on the current row.
-
Refund and chargeback rates computed over windows that extend past t. Post-upgrade recurring billing changes dispute behavior. Fix: hard-cap all aggregation windows at t on the ingestion timestamp.
-
Late-arriving transactions. A charge on 2025-07-01 may be posted to the data warehouse on 2025-07-10. Filtering on transaction date only lets future-ingested rows into a "pre-T" feature. Fix: filter on
ingested_at ≤ t, notcharged_at ≤ t. -
Test-mode subscription objects or CRM "opportunity stage" fields. Both may be written because of the upgrade event itself. Fix: treat test-mode objects as legitimate pre-signal only if created strictly before t; exclude CRM fields that are updated reactively.
-
Target encoding or scaler fitted on the full dataset. Mean-encoding a vertical category using future snapshots embeds outcome information into training features. Fix: fit all encoders and scalers inside each training fold, never before the fold split.
-
Random train/test splits across overlapping snapshots. A merchant at snapshot t₃ may appear in the test set while the same merchant at snapshot t₁ is in the training set with a partially overlapping label window. Fix: time-based splits with a 60-day gap between the end of the training label window and the start of validation.
-
Intent signals that duplicate the label. Pre-T docs-page views for the billing product are a legitimate high-signal feature. A test-mode subscription object created at t − 1 day is borderline — include it deliberately and document the decision rather than discovering it accidentally.
(c) Features (all computed as of t)
Recency / frequency / monetary
- Days since last charge
- Charge count over the last 30, 90, and 180 days
- Gross volume over the last 30, 90, and 180 days (log-transformed)
- Median ticket size and its coefficient of variation
Recurring-billing behavioral signals 5. Share of customers with ≥ 2 charges spaced 28–35 days apart 6. Share of volume from customers billed the same amount ± 2% on a monthly cadence 7. Median inter-purchase interval per repeat customer 8. Share of charges processed off-session or using a saved payment method
Customer structure 9. Distinct card fingerprints per charge (payment diversity) 10. Repeat-customer rate (fingerprints with ≥ 2 charges) 11. Top-10 customer volume share (concentration / HHI) 12. New-customer share over the last 30 days
Timing signals 13. Weekend share of charges 14. Day-of-month entropy — low entropy indicates billing-cycle clustering 15. Count of distinct price points — few recurring amounts suggest plan-like behavior
Risk indicators 16. Refund rate over 90 days 17. Dispute / chargeback rate over 90 days
Growth 18. Volume growth: last 30d vs. prior 30d 19. Charge-count growth: last 90d vs. prior 90d
Metadata 20. Account age in days 21. Vertical / MCC (as-of historical value) 22. Country and region 23. Business type (individual vs. company) 24. Active product surface: Invoicing, Payment Links, Checkout (binary flags) 25. Billing-docs page views before t (pre-T intent signal)
(d) Modeling
Model A — L2-regularized logistic regression. Log-transform and winsorize continuous features, one-hot encode vertical and region, add missing-value indicators. Naturally well-calibrated, interpretable coefficients map cleanly to reason codes for sales. Strong baseline with predictable behavior.
Model B — Gradient-boosted trees (LightGBM or XGBoost). Captures interaction effects (e.g., SaaS vertical × high monthly-repeat share) and handles sparse or missing features natively. Expect materially higher PR-AUC than logistic regression. Use early stopping evaluated on a time-held-out fold.
Class imbalance (expected base rate: 1–3%). Prefer class weighting over resampling — scale_pos_weight in XGBoost or class_weight='balanced' in scikit-learn — and tune solely on PR-AUC. If downsampling negatives for speed, correct predicted probabilities afterward by adjusting the log-odds by log(1/r) where r is the negative sampling rate. Avoid SMOTE: synthetic merchants with temporal features are semantically meaningless.
Calibration. Fit isotonic regression (or Platt scaling for smaller datasets) on the most recent held-out snapshot, never on training data. This step is mandatory for threshold selection in part (e).
Sales interpretability. Surface the top 3 SHAP contributions per merchant translated into plain language ("68% of revenue comes from customers billed monthly at a fixed amount"). Apply monotonic constraints in the GBT for directionally obvious features (recurrence-share, repeat-customer rate) to prevent counterintuitive explanations.
(e) Evaluation and threshold selection
Rolling-origin cross-validation. For each validation snapshot v (e.g., 2025-03, 2025-04, 2025-05-04), train on all snapshots where the label window ends at least 60 days before v, leaving a gap to prevent overlap. Evaluate on v. Average metrics across folds; watch for performance degradation over time as a signal of concept drift.
Metrics. Primary: PR-AUC and precision@1000. Secondary: recall@1000 and calibration error (ECE). Accuracy and ROC-AUC are misleading at 1–3% base rates.
Threshold selection for the 1,000-merchant list. After calibration, rank merchants by predicted probability descending. Read the precision value at rank 1,000 off the precision-recall curve on the most recent validation fold. If precision@1000 ≥ 0.60, that cutoff probability is your deployment threshold. If not, shrink the list until the precision target is met and report the trade-off to the business team. Re-evaluate this threshold monthly as the score distribution shifts.
(f) Post-deployment monitoring
Feature drift. Compute the Population Stability Index (PSI) weekly for the top 15 features between the training distribution and the live scoring population. PSI > 0.2 on any critical feature triggers investigation; PSI > 0.25 triggers a retraining review.
Label drift. Track the 30-day rolling conversion rate among scored merchants. A sustained drop of more than 30% relative to training base rate indicates the population has shifted.
Calibration drift. Every 30 days, once enough labels have matured, compute the Expected Calibration Error on scored merchants. Plot a reliability diagram. Significant deviation from the diagonal means recalibration is needed even if the ranking is still good.
Retraining safely. When retraining, construct new snapshots using only cutoffs tᵢ where tᵢ + 60d is fully in the past. Never include a snapshot whose outcome window overlaps with the current calendar date. This preserves temporal correctness on every retraining cycle and prevents future labels from contaminating the new model.
Common mistakes to avoid. Treating already-paid merchants as negatives, filtering on transaction date instead of ingestion date, random-splitting across overlapping snapshots, and fitting encoders before the fold split are the four errors that most often go unnoticed until post-deployment performance collapses.