Computing Library › Machine Learning
Machine Learning

Data Leakage

Data leakage lets information unavailable at prediction time slip into training, inflating scores that collapse in production.

The most common way to fool yourself

Data leakage occurs when a model is trained using information it would not have at prediction time. The model learns to exploit that information, so validation and test scores look excellent, and then performance collapses in deployment. Leakage is subtle, widespread, and responsible for many machine-learning projects that fail after promising evaluations.

Common sources

Kronos motion — lego machine

How to prevent it

Split the data first, then fit all preprocessing on the training portion only and apply it to the rest. Wrap every transform in a pipeline so it is refit inside each cross-validation fold. For time series, split by time and never shuffle. Use grouped splits to keep related records together. Scrutinize any feature that seems too predictive, it is often leakage.

python
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
pipe = make_pipeline(StandardScaler(), model)   # scaler refit per fold
cross_val_score(pipe, X, y, cv=5)

The tell-tale sign

Suspiciously high performance is the classic symptom, an accuracy far above what the problem should allow. When results look too good, hunt for leakage before celebrating. Honest evaluation depends on a strict boundary between what the model may see during training and what it must predict, enforced by a sealed test set.