Concept · Chapter 3: Machine Learning
Data Leakage
Data leakage is when training or evaluation data contains information that won't be available when the model is actually used — making results look far better than they really are.
The problem
Models are excellent at finding any signal that predicts the label — including signals that are accidents of how the data was collected or split.
The solution
Build features only from information available at prediction time, split data before any preprocessing, split by time or by entity where appropriate, and keep test data untouched.
The consequence
Leakage is one of the most common reasons impressive ML results fail in production — and, for LLMs, 'contamination' of benchmarks by training data is a major evaluation concern.
You should understand first
- The Turing Test
- Symbolic AI
- Logic and Rules
- Expert Systems
- Knowledge Representation
- The Knowledge-Acquisition Bottleneck
- From Rules to Learning
- Supervised, Unsupervised and Self-Supervised Learning
- Vectors
- Features, Labels and Tasks
- Loss Functions
- Derivatives and Gradients
- Gradient Descent
- Linear Regression
- Probability and Distributions
- Expected Value and Variance
- Sampling and Uncertainty
- Generalization, Overfitting and Underfitting
- Data Leakage
Three classic ways it happens
Target leakage
Predicting whether a patient has pneumonia, with a feature "took antibiotics". Antibiotics are prescribed because of the diagnosis — the model learns the consequence, not the cause, and is useless before diagnosis.Preprocessing leakage
Normalizing or imputing with statistics computed on the whole dataset, then splitting. Information about the test set has flowed into training.Split leakage
Random splits when rows aren't independent: the same customer appears in train and test, or tomorrow's data trains a model evaluated on yesterday. The model is tested on near-copies of what it memorized.
As a data engineer you're unusually well placed here: most leakage is a pipeline problem — joins that pull in future information, features computed at the wrong point in time, deduplication done after the split.
The LLM version: contamination
When benchmark questions (or close paraphrases) appear in a model's pretraining data, its benchmark score overstates its real ability Established. Because pretraining corpora are web-scale and often undisclosed, measuring how much contamination affects reported LLM results is an active research area Active research — covered in Chapter 16.
What to remember
- Leakage = information in training/eval that won't exist at prediction time.
- Target leakage: a feature that is a consequence of the label.
- Split before you preprocess (fit scalers/encoders on train only).
- For time series, split by time; for users/patients, split by entity.
- LLM version: benchmark questions appearing in pretraining data.
Key papers
Leakage in data mining
Shachar Kaufman, Saharon Rosset et al. · 2012 · ACM Transactions on Knowledge Discovery from Data
Named and systematized data leakage — information in training data that won't exist at prediction time — one of the most common ways ML results turn out to be fake.