Metrics & Evaluation

Data Leakage

0.99 AUC in the notebook, 0.61 in production. Every time, it's leakage.

🟡 intermediate4 min readevaluationmust-know
Leakage is any information in training that will not be available at prediction time. It comes in three flavours: target leakage (a feature is a consequence of the label), train–test contamination (preprocessing or duplicate rows cross the split), and temporal leakage (training on the future). The symptom is performance that looks too good and collapses in production. The defences are a strict per-fold pipeline, point-in-time correct feature joins, and asking of every feature "would I have known this then?"

The three families

1. Target leakage. A feature encodes the outcome. account_closed_date in a churn model. num_collection_calls in a default model. days_in_ICU for a mortality model. These are consequences of the label, generated after the decision point.

Detection: if a single feature carries suspiciously high importance, interrogate it. Ask the data owner when the column is populated in the source system. If the answer involves anything downstream of the event, drop it.

2. Train–test contamination. Information crosses the split:

3. Temporal leakage. The model sees the future:

Point-in-time correctness

The industrial answer, and the reason feature stores exist. Every feature must be computed from data whose timestamp is strictly before the prediction timestamp. A backfill that joins on entity ID alone, ignoring event time, is the single most common source of silent leakage in production ML — and the direct cause of training–serving skew, where offline metrics look great and online performance does not match.

Practical guard: build features via an as-of join keyed on (entity_id, event_time), and add a gap equal to your prediction horizon.

Your checklist

Say this out loud

"Anything that looks too good is leakage until proven otherwise. I'd check three things: whether any feature is a consequence of the label rather than a predictor, whether preprocessing or duplicate rows crossed the split, and whether features are point-in-time correct relative to the prediction timestamp. The structural fixes are per-fold pipelines, grouped or time-based splits with a horizon gap, and as-of joins on event time."

Check yourself

Question 1 of 3

Which feature most clearly leaks in a loan-default model?

More in Metrics & Evaluation

See all →
Precision, Recall & F14 minWhy Accuracy Lies4 minROC-AUC vs PR-AUC4 min