Skip to content
Road to Intelligence

Concept · Chapter 3: Machine Learning

Data Leakage

Must knowKnow well15 minDifficulty

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.

Three classic ways it happens

  1. 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.
  2. Preprocessing leakage

    Normalizing or imputing with statistics computed on the whole dataset, then splitting. Information about the test set has flowed into training.
  3. 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

Important

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.

~45 min readdoi:10.1145/2382577.2382579✓ verified 2026-09-26