Data Leakage

Data leakage occurs when model development or evaluation uses information outside the intended prediction or assessment boundary. The scikit-learn guide describes the case where information unavailable at prediction time is used in building the model. Test feedback can also compromise an assessment that is supposed to be independent of selection. Leakage can make scores misleadingly favorable, but its effect need not have the same direction or size in every dataset. Overfitting and leakage are distinct and can coexist: fitting sample-specific patterns is not the same as crossing an information boundary.

Four common forms

Target leakage. A feature contains the answer or a consequence known only later. Examples include amounts recovered after default or a fraud flag set after chargeback confirmation. A model that exploits such features can look much better in testing than it will when those values are unavailable. Ask when each field becomes known relative to prediction, and reconstruct the data available then, using a point-in-time join where appropriate.

Train-test contamination. Evaluation information influences fitting or selection. Scaling with statistics from the full dataset is one route. Split first, fit preprocessing and feature selection only on the training partition, and apply the learned transformation to evaluation data. In cross-validation, fit that whole procedure inside each training fold. A Pipeline helps keep these steps together when fitted on the correct partitions; it does not identify or exclude test rows passed to fit. Check duplicates and near-duplicates against the evaluation’s intended new-case target as well.

Temporal leakage. An assessment uses future information, such as March volume to predict January prices. Time-ordered splitting prevents some future-to-past mixing but does not repair a feature computed from later events. Check feature and label availability at every training and prediction cutoff, including delayed labels, rolling windows, preprocessing, and data revisions. Use gaps or purging where the outcome windows and dependencies require them. A January/February split still leaks if each row includes its own outcome recorded a month after prediction.

Group leakage. When the target is performance on new patients, customers, devices, or sessions, related records in training and evaluation can make that assessment optimistic. Hold out groups for that target. If deployment instead predicts later events for existing customers, overlap can be appropriate under a valid time and information boundary. Group separation alone does not remove future features or preprocessing leakage; some tasks need both group and time constraints.

Finding it

Unexpectedly high scores, a dominant feature, or a post-deployment drop are reasons to investigate, not diagnostic proof. Audit data provenance, availability times, split membership, preprocessing fits, and access to evaluation results. Reconstruct suspect features and compare suitable evaluation designs. training-serving skew concerns differences between development and serving data or transformations; leakage concerns information crossing the intended boundary. Both can occur in the same system, and neither requires one particular pattern of scores.

In language model evaluation

For language models, an evaluation set may influence a system through demonstrations, fine-tuning, repeated prompt selection, or pretraining exposure. This can compromise an independent generalization estimate without making the examples useless for development or regression checks. Record known overlap and selection history; avoid treating a benchmark score as either pure memory or pure ability without evidence. Fix candidates and rules before independent confirmation, and account for adaptation after repeated release verdicts. Sealing or refreshing a set is useful only with the corresponding independence and sampling conditions. The Judge Preferred Longer Answers explains the release workflow; Train, Validation, and Test Sets without Data Leakage gives the predictive-model treatment with code.

References:


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.