Watch feature-selection leakage
The visualizer generates random labels and noise features. Choose Once, dataset to select features using every row before cross-validation. Because selection has seen labels from later validation folds, some noise features may look predictive by chance and raise the reported score above the chance baseline.
Now choose Inside each fold. Feature selection is repeated using only that fold’s training rows, then evaluated on its held-out rows. This is one random simulation, not a fixed expected score; with random data, results vary around chance.
This shows how leakage can enter through a model-selection decision, not only through a column that directly reveals the answer.
Suppose a scaler computes a mean and standard deviation using the full dataset, or an imputer estimates a median from all rows. Validation and test examples have influenced the transformation before evaluation. Fit preprocessing on the training fold only, then apply the fitted transform to held-out data. A cross-validation Pipeline makes that order explicit.
Feature selection, target encoding, dimensionality reduction, and resampling also learn from data and must be fitted inside each training fold. A fixed transformation such as converting Celsius to Fahrenheit has no learned parameters, so it does not create this form of leakage.
Leakage can come from the data definition
- Future information: a customer-status field updated after the event being predicted may reveal the outcome.
- Related records across splits: repeated scans from one patient or duplicate documents can make validation examples nearly identical to training examples. Split by patient or document group when deployment requires generalizing to unseen groups.
- Time order: random splitting can train on future periods and evaluate on earlier ones. Use a forward time split when predicting the future.
- Target construction: a feature derived from the label, directly or indirectly, can encode the answer.
These problems cannot be solved by a pipeline alone. Define what information exists at the moment of prediction and ensure the split reproduces that setting.
A practical check
For every feature, ask when it is recorded and whether it could change after the prediction point. For every preprocessing step, ask which rows were used to fit it. For every split, ask whether a related entity or a later date appears on both sides. Document the answers before trusting a score.