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_reasonandmembership_fee_refundedall exist only because the member cancelled. - Time leakage: a feature computed with data from after the prediction moment. An
avg_orders_per_monthworked 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.