Level 2 · Module 11 · 10 minutes
Leakage: when the answer sneaks into training
- Define leakage and explain why it makes results look better than they are.
- Name several ways leakage enters, including leaked features, duplicate rows and future data.
- Describe a simple feature audit and the habit of splitting before preparation.
Leakage is information that would not be available at the moment a decision must be made, but that sneaks into training or testing. The model then looks brilliant during checks and fails in real use, because the special knowledge disappears. Leakage is one of the most common reasons a promising model disappoints.
How leakage happens
- The answer is hidden in a feature. Predicting a refund outcome with a column that is recorded when the refund is paid is not prediction; it is copying the answer.
- The same record or person appears in training and test. Duplicate rows make the test pile recognisable from memory.
- Future information is used in training. A model that learns from next month's sales cannot forecast next month.
- A cleaning or scaling step is fitted on all rows before splitting, so test statistics shape training.
- An identifier or ordering column encodes the answer without looking like it should.
Spotting it
The clearest warning is a score that is far better than the work can justify, especially with very few features. Another warning is a feature whose influence looks impossible for the task. Write a simple table of every feature and ask: would this value really be known when the decision is made? If the answer is no, the feature must go.
Preventing it
Split first, then fit all preparation steps on the training rows only and apply them to validation and test. Keep all rows for one person, shop or order in one pile. For time-based questions, split by time. Keep a list of decisions about which features are allowed and why, and review it with someone who knows the process. A model that cannot use leakage may score lower, and that lower number is the honest one.
Why it is a design problem, not just a coding bug
Leakage usually enters when someone chooses the columns or defines the label, long before any code runs. A person who knows the business process can spot a feature recorded after the outcome. That is why the audit belongs to the project team, not only to the engineers who fit the model.
Practice versus real training
Auditing a written feature list at a desk is a simplified teaching picture of leakage checking. Real training pipelines and commercial reporting need the same audit built into their steps. No model is trained in this lesson; the audit is done on paper.
Common misconception
Leakage is a coding bug that only programmers can cause. Leakage is usually a design mistake. It comes from choosing features that would not be available at decision time, from duplicated or future rows, and from preparing data with test rows included. Anyone who helps define the question and the columns can prevent it.
Guided practice
Write a list of eight hypothetical features for a model that predicts whether an invoice will be paid late, such as invoice amount, payment history, due date and a column recording the payment date. Beside each, write yes or no to the question: would this be known at the moment the invoice is issued? Remove every no. Then explain what a suspiciously strong score with only two features might mean. No model is trained.
Knowledge check
Independent practice
Write a short example from your own work or daily life and decide whether it is AI, ordinary software or a mixture. Then explain why. Save it in your notes; no account is required.
Last reviewed: · Report a problem