Applied Case — The Leakage & Bias-Variance Clinic
P5.applied-cases.04 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Applied Case — The Honest Tabular Model, End to End
P5.applied-cases.04 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Applied Case — The Honest Tabular Model, End to End
The end-to-end case built the discipline; this clinic shows what its absence looks like — from the inside. Three notebooks — runnable documents mixing code and results — each scoring far too well, each broken in a different way. The diagnosis pattern is always the same: a score that good is a symptom. Your job in each is to name the leak, fix it, and reproduce the honest number.
Every leak has the same anatomy: information that will not exist at prediction time is present at training time. The model is not wrong to use it — gradient descent has no ethics — the evaluation is wrong to reward it. And because the leak inflates precisely the number you use to judge the model, the better the score looks, the harder the production collapse.
| Leak | Mechanism | This clinic's numbers |
|---|---|---|
| Target leak | A feature caused by the outcome | 0.95 → honest 0.80 |
| Duplicate leak | Twin rows straddle the split | 0.80 → honest 0.61 |
| Temporal leak | Random split hands the model the future | 0.84 → honest 0.73 |
In bias-variance language (Model Evaluation & Selection): a leak fakes a variance reduction — the model looks like it generalises because the "unseen" data secretly is not. The honest fix usually raises measured error while lowering deployed error. That trade is always worth taking, and explaining why is a favourite senior-interview probe.
| Type | Resource |
|---|---|
| In-app | P5.applied-cases.01 — The Honest Tabular Model — the discipline whose absence this clinic dissects |
| In-app | P5.ml-methods.05 — Time Series & Data Issues — drift, regimes and time-respecting evaluation |
| In-app | P5.ml-methods.06 — Model Evaluation, Selection & Interpretability — leakage, generalisation and the bias-variance frame |
| External | scikit-learn user guide — Common pitfalls and recommended practices: data leakage |
| External | Kapoor & Narayanan (2023), Leakage and the reproducibility crisis in ML-based science — the taxonomy this clinic teaches, measured across 294 published papers |
Practise this lesson's 3 self-checks
One per screen: you reveal each answer and mark it yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Four broken notebooks, one per trap — each with the seeded dataset, the inflated score reproduced in front of you, and hidden tests that only pass when the leak is found, fixed, and the honest number lands in the reference band. The traps run in-browser (Pyodide) — instant, no kernel queue. The senior rung hides the subtlest species: every step looks correct, yet pure noise scores 71%.
Loading exercise…
Loading exercise…
Loading exercise…
Loading exercise…
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...