Data Leakage: The Silent Killer of Model Performance
Several earlier pages in this track quietly flagged the same underlying bug from different angles. This page names it, and ties every instance together.
Advanced
| Type | What happens |
|---|---|
| Target leakage | a feature itself encodes information that wouldn't exist yet at the moment a prediction actually needs to be made |
| Train-test contamination | information from validation/test data leaks into how the training data — or the preprocessing applied to it — gets prepared |
manual_intervention_flag — whether an engineer stepped in to investigate the run.
It would almost certainly turn out to be a spectacular predictor of "fail." It's also
completely useless, because it's only ever set after a human has already noticed the
run failing — by definition, the model needs to predict failure before that happens,
and at that moment, the feature hasn't been set for anything yet. Training on it produces a
model that looks nearly perfect on historical data (where the flag was always set correctly,
in hindsight) and is worthless the moment it has to predict a brand-new run in real time.
| Where this track already covered it | The contamination |
|---|---|
| Feature Engineering — scaling | fitting a scaler's mean/std on the full dataset before splitting, instead of on the training split alone |
| Feature Engineering — target encoding | computing a category's average target value from rows that include the very examples being predicted |
| Train/Test Splits & Cross-Validation — near-duplicates | rows from the same PR (near-identical, same outcome) split across both training and test |
| Train/Test Splits & Cross-Validation — time order | a random shuffle mixing "future" and "past" rows across a genuinely time-ordered split |
model.feature_importances_ from Ensemble
Methods and finding one feature towering over every other by a wide margin is a strong
signal to go investigate that specific feature's timing before trusting the result.
lines_changed and
touches_slow_suite pass — they're known the instant the run is triggered.
manual_intervention_flag fails — it doesn't exist until well after the outcome is
already known. Running every feature through this question before training is cheap insurance
against the entire category of bug this page covers.
Pipeline
before handing it to cross_val_score or train_test_split-based
validation, rather than manually calling .fit_transform() on the whole dataset up
front and hoping to remember the right order every time.
feature_importances_,
the diagnostic tool this page's red-flag check depends on.