What is data leakage, how do you detect it, and how do you prevent it in a modelling project?
What the interviewer wants to hear
- Leakage is information in training that will not exist at prediction time
- Signs include suspiciously high scores and a single dominant feature
- Common causes: future data, label-derived features, preprocessing on all data, duplicate entities across splits
- Prevent with point-in-time features, pipelines and proper splits
Model answer
Leakage is when the model learns from information that will not be available when it makes real predictions, so offline scores look great but production results do not. Warning signs are scores that seem too good, like 0.99 AUC on a hard problem, or one feature dominating importance. I investigate those features and ask when each value becomes known. Common causes are features derived from the label, such as a refund flag in a fraud model, using future data in time series, fitting scalers or encoders on the whole dataset before splitting, and the same customer appearing in both train and test. To prevent it I build features with point-in-time logic using an as-of timestamp, put all preprocessing inside a pipeline that is fitted on training folds only, split by time or entity when needed, and finally compare offline metrics with a short shadow run in production.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Data Scientist questions
- Walk through how you would design an A/B test for a new checkout page.
- How would you choose a success metric for a new "recommended for you" section in a shopping app?
- You have 500 candidate features for a churn model. How do you decide which ones to keep?
- A business team does not trust your credit risk model. How do you explain its predictions?
- The CEO asks: "Why are customers churning?" How do you approach this?
- You are building a model where only 0.5% of examples are positive. How do you approach training and evaluation?
- How would you validate a demand forecasting model before the business relies on it?
- How do you decide between a regularised linear model and a gradient boosted tree model for a tabular problem?
- Walk me through how you would decide the sample size and duration of an A/B test.