What is data leakage, and what are two examples you could plausibly meet in practice?
Foundations, Model selection
Level L2 Elementary. Length Short. Nature Th Theoretical.
What's being asked
Whether you know that a model must only see, during training, information it will also have at prediction time, and can spot where that rule quietly breaks.
Key idea
Data leakage is when information that will not be available at prediction time (the test labels, the future, or the target itself) gets into training or model selection. The validation score then looks better than the model really is, and the model disappoints once it is deployed.
Steps
- Define it in one line: the model learns from something it should not have, so the evaluation is over-optimistic.
- Example 1, preprocessing on all the data: you standardise features, fill missing values or pick the "best" features using the whole dataset before splitting. The test set has then shaped the training. Fit every such step on the training folds only, for instance inside a scikit-learn Pipeline.
- Example 2, a feature that gives the answer away: predicting whether a patient has pneumonia with a "took antibiotics" column, or predicting loan default with a "number of collection calls" column. Both are recorded after the outcome, so they will not exist when you predict.
- A third common case is time: randomly splitting time-series or repeated records of the same customer, so the model trains on the future, or on near copies of test rows. Split by time or by group instead.
- Say how you catch it: a score that is suspiciously high, one feature with an outsized importance, or a big drop between validation and real use.
Common mistakes
- Thinking leakage only means "the test set was in the training set". Most leakage is subtler: preprocessing, feature selection or tuning done on all the data.
- Tuning hyperparameters on the test set and then reporting the test score as the final result. Use a separate validation set or cross-validation, and touch the test set once.
How long your answer should be
A one-line definition and two concrete examples, each with its fix: about 4–6 sentences.
Last checked on 4 December 2026.
Read this
Previous in Foundations: What are the three mechanisms of missing data — MCAR (Missing Completely At Random), MAR (Missing At Random) and MNAR (Missing Not At Random) — and what is an everyday example of each?
Next in Foundations: Your model has 2% training error and 25% validation error. What is the problem, and what would you try? What if instead both errors were about 24%?