Quick answer: Split your data before learning preprocessing settings. Fit transformations on the training subset, then apply those learned settings to the test subset. If the test set influences a scaler, imputer or feature selector, it can influence the model before evaluation begins.
The quiet source of optimistic scores
The official scikit-learn pitfalls guide defines leakage as using information unavailable at prediction time while building a model. Its examples show that preprocessing can introduce this problem even when the final estimator is fitted only on training rows.
Consider a notebook with a cell called “clean the data” followed by another called “split the data.” That order deserves inspection. The label sounds harmless, but the first cell may estimate quantities from every row. The right review question is what each operation learns and which rows it can see.
Distinguish learning from applying
The documentation distinguishes fit and fit_transform, which learn from inputs, from transform, which applies learned settings. It recommends pipelines to keep transformations with estimators, including during cross validation.
An original notebook review can record three items for every step: its inputs, any state it learns and where that state is reused. If the notebook loses this distinction in temporary variables, rename them so a reviewer can trace the boundary.
For example, “all_clean” is a weak description when its contents depend on a fitted transform. A name and note that identify the training subset and fitted object make the dependency easier to inspect. Good naming does not prevent leakage by itself, but it can expose the operation that needs review.
Feature selection belongs inside the review
The guide warns that choosing features with test information can inflate results. It illustrates the effect using random targets, where an incorrect feature selection order produces an apparently useful score. The example is a teaching demonstration, not a performance claim about your dataset.
When an experiment produces a surprising improvement, inspect the sequence of operations before inventing a story about model quality. Retain the previous version of the notebook so you can compare the data flow and identify what changed.
Ask an AI assistant for a dependency audit
This original prompt focuses an assistant on observable operations rather than asking it to endorse a score:
Review this permitted training notebook for preprocessing leakage. List each fitted transformation and its input variables. Trace those variables back to the split that produced them. Flag steps whose fit may include evaluation rows. Separate confirmed dependencies from uncertain ones. Suggest a minimal correction and name what should be rerun. Do not invent execution results or claim the score is valid.
Check the returned findings against the actual code. An assistant may miss a helper function or misunderstand a variable created in another cell. The prompt is an inspection aid and has not been executed as part of this article.
Keep the corrected result separate
If you find a boundary error, save the original result with an explanation and run the corrected workflow. Do not simply relabel the old score. Record the code revision, data split, preprocessing steps and actual new output.
A lower corrected score can be more useful than an impressive score with an unclear evaluation boundary. It tells you where the experiment stands and gives later changes a more credible baseline.
Related: our dataset preview guide discusses another evaluation limit: a few inspected records do not establish corpus quality.
Illustrative reading photograph: Yen Vu / Unsplash, under the Unsplash License. Not a notebook screenshot or experiment result.
Sources
Documentation checked October 16, 2026. Written with AI assistance. This evergreen guide reports no new benchmark or executed model training.
