KatInterview

Build an End-to-End User Purchase Prediction System

Machine LearningModel answer
HardModel answerMachine Learningpropensity-modelingcausal-inferenceproduction-ml

Last updated

Design a complete ML pipeline to predict which users will buy after receiving a promotional message, handling causality, cold starts, and production deployment.

You're building a machine learning system for a two-sided marketplace that wants to send targeted promotional notifications. The business rule is simple: each day, score all active users and send promotions to the top 20% most likely to convert.

Your task is to design the complete modeling pipeline, covering:

Label Construction & Data Leakage
Define how you'll label training examples to predict "will this user purchase in the next 7 days if we message them today?" Many users have already received messages historically—how do you avoid contaminating your labels with post-treatment signals? Should you train on everyone who was messaged, or apply additional filters? How do you handle users who receive multiple promotions?

Feature Engineering
Propose concrete features that capture user behavior, preferences, and context. Explain how you'll enforce temporal consistency (no information from the future) and prevent training-serving skew when the model runs daily in production.

Handling Imbalance & Ensuring Calibration
Purchase rates are low (around 3%). Choose appropriate techniques for class imbalance and explain how you'll calibrate probabilities. Why does calibration matter here? Describe your monitoring and recalibration strategy.

Offline Validation Strategy
Design your evaluation approach: which metrics matter, how to construct train/test splits for time-series data, and what slice-level analyses you'll perform to catch issues before production.

Estimating Incremental Impact
The real business value isn't just "probability of purchase" but "incremental purchases caused by the message." Using only historical observational data (no past A/B tests), how would you estimate whether your targeting policy actually drives incremental revenue versus just messaging people who would have bought anyway?

Production Rollout & Monitoring
Describe your online testing plan: what holdout strategy, what metrics to monitor, how to detect and respond to distribution shift, and when to retrain.

Cold Start Problem
How will you score brand-new users on their first day, and how will you iteratively improve as more data arrives?

Assume 50M daily active users, targeting the top 10M, with a baseline conversion rate around 3% over 7 days.

Hints

Hint 1

Think about the difference between correlation and causation—ranking users who are likely to buy is not the same as ranking users who buy *because* of the message.

Hint 2

For temporal data, your train/test split must respect time. Random shuffling will leak future information into your training set.

Hint 3

Calibration matters when downstream decisions use expected values (e.g., expected revenue × probability - cost), not just relative ranking.