Skip to the workspace
Pebellslearn by building
Evaluating Models  ›  Capstone Project

Data Leakage

Machine Learning 15 minLeakage happens when training data contains information that will not exist when the model is used, such as features created by the outcome or computed from the future, and it makes offline scores look far better than live results.

ai data scientist / Data Leakage

Explore each scene at your own pace.

01 · The rule

The rule

Data Leakage

A colleague's new churn model scores a precision of 0.97 and a recall of 0.98 on August, far beyond anything before it. Its most important feature is exit_survey_sent. Pantry sends that survey the moment a member presses "cancel". The model has not learned to predict cancelling; it has learned to notice that a cancellation already started. Live on the 1st of the month, when nobody has pressed anything yet, it will be close to useless.

The rule

Every feature must be knowable at the moment you predict.

Leakage is information in the training data that will not be available when the model is actually used. It makes offline scores look wonderful and live results disappoint. It comes in three common forms:

  • Target leakage: a feature created by the outcome itself. exit_survey_sent, cancellation_reason and membership_fee_refunded all exist only because the member cancelled.
  • Time leakage: a feature computed with data from after the prediction moment. An avg_orders_per_month worked out over the whole year includes the very months you are trying to predict.
  • Train–test contamination: information from validation or test rows seeping into training. Filling blanks with the mean of all rows, scaling with statistics from the full dataset, or letting the same member appear on both sides of a split all do it.

The warning signs are consistent: a score that seems too good to be true, one feature that dominates everything, and a model that shines offline but falls flat in production.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.