Data leakage and misleading results
A high score is useful evidence, but it does not prove a model will work in real use. Follow the clues that can make an evaluation look better than it is.
What a high test score can miss.
A test set is a held-back group of examples used to estimate how a model may perform on new examples. Its test score summarizes performance on that group; it is an estimate, not a guarantee.
A data split assigns examples to separate groups for learning and checking. The training set is the group used to fit a model; keeping the test set out of training makes the check more informative.
Data leakage happens when information that would not be available in real use influences model training or evaluation. The score can then reward a shortcut instead of the pattern the model needs to learn.
We will follow three possible routes: a clue from after the decision, repeated or related examples across the split, and preparation that uses held-back data. Then you can audit a delivery example.
Northside wants to predict at 8:00 AM dispatch whether each parcel will arrive late by 6:00 PM. We will ask what information is fair to use at dispatch and whether the offline check resembles next week’s parcels.
In the earlier lesson on training, validation and test sets, the test set was kept for a final check. A separate test set helps, but it cannot fix every way information may leak into a pipeline.
Target leakage: a clue from after the decision.
The prediction moment is when a model must make its real decision. The target is the outcome it is trying to predict, and a feature is an input it can use. Target leakage occurs when a feature reveals the target using information unavailable at the prediction moment.
Imagine taking a practice quiz with the answer key printed on the page. Doing well on that quiz says little about how you will do when the key is gone.
Northside’s old records include parcel weight, route, and whether a delay refund was issued. Refunds are issued after a parcel arrives late. Using that column to predict lateness at 8:00 AM gives the model a clue that will not exist when it makes a live prediction.

A similar mistake could happen in a subscription model: a cancellation survey sent after someone cancels cannot help predict, on the first day of the month, who is still active and may cancel later.
Duplicate overlap: the test has seen a copy.
Duplicate overlap means the same record, or a copied version of it, appears in both training data and the test set. The score may partly measure recognition of a record already seen.
A random row split assigns individual rows to groups without keeping related rows together. It can be a poor match when repeated records or shared identities matter.
A scanner re-imports Northside’s Order #104. A random row split places the original order in training and its copy in the test set. A strong score on that test does not show how well the model handles a genuinely new order.

Group overlap is related but not identical: different records from the same person, account, or event appear in both sets. If the goal is to work with new patients, for example, two scans of one patient should usually stay together. If the goal is a later scan from a known patient, a time-based split may better match the question. Choose the split to match the intended use.
Preprocessing leakage: test data shapes preparation.
Preprocessing means preparing inputs before a model uses them, such as filling missing numbers or scaling values. To fit a preparation step is to calculate the values it will use from a chosen data group. Preprocessing leakage happens when this calculation includes held-back test examples before evaluation.
Suppose Northside fills missing travel times with an average. If it calculates that average using every week before separating the last week for testing, information from the test week has shaped the training inputs. Instead, split by week, calculate the average from training weeks, and reuse that value for the test week.

Audit Northside’s delivery pipeline.
The worked examples showed what to look for. Now inspect four illustrative pipelines. Compare each offline test score with a new week’s live score, identify the cause of any gap, then apply a fix.
- Start with the refund column. Compare every feature with the 8:00 AM prediction moment, choose a diagnosis, and apply the fix.
- Inspect the duplicate-order and whole-table preparation cases. Notice which part of each pipeline creates the concern.
- Finish with the time-based, train-only preparation case. Ask whether its test setup resembles the next week of parcels.
- Prediction moment:8:00 AM warehouse dispatch
- Features used:Parcel weight, route zone, forecast rain, Customer delay refund issued
- Split rule:Split by week (past weeks train, last week test)
- Prep order:Scaling fit on training weeks only
Illustrative simulation: these percentages are invented teaching values to show how leakage inflates offline test scores compared with live performance, not measurements from a live production model.
A short audit before trusting a score.
- 1. Name the prediction momentRemove inputs recorded after the model must decide.
- 2. Check records and groupsRemove accidental copies. Keep related examples together when the evaluation is meant to test unseen people or events.
- 3. Match the split to the useFor a future prediction, training on earlier periods and testing on a later period may give a more relevant estimate.
- 4. Fit preparation on training dataLearn averages, ranges, and encodings from training data, then apply those values to validation and test examples.
- Does a high score prove the model is good?
No. Check whether the evaluation is fair and whether the score matches the real task before relying on it.
- Is every high score caused by leakage?
No. A task can be predictable. An unexpectedly high result is a reason to audit the data and split, not proof of a leak.
Check your understanding.
Take this with you.
A high score earns trust only after a fair check. Future clues, duplicate or overlapping records, and preparation fitted on test data can make results look better than performance on new cases. Match the test to the real decision, then inspect how every feature and preparation step got there.