Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 03 / Topic 5 of 6

Data leakage

Leakage is any path by which information about the answer (or the test set) reaches the model at training time. It is the most common way ML projects fail quietly: scores look great until production.

The classic cases:

Leak Example
Test data in preprocessing Scaling or imputing with statistics over all rows
Target leakage A feature recorded after the outcome ("account closed date" when predicting churn)
Time leakage Training on March data to predict January
Duplicate rows The same customer in both train and test

The symptoms: a test score that looks too good, and a production model that falls apart. The defences: split first; fit preprocessing on train only (Pipelines make this automatic — Part 5); ask of every feature, "would I have this value at prediction time?"

🧪 Quick quiz

  1. Which feature is a leakage risk when predicting churn: tenure, monthly charges, or "account closed date"?
Show the answer

"Account closed date" — it is only known after the customer left, so it will not exist at prediction time.

Done here? The practice set for Part 3 — 4 exercises with solutions — is on the part page.

Search the guide