# A leakage-safe evaluation checklist for machine learning

Where test information sneaks into an experiment, how to catch it with a tiny split audit, and what to freeze before reporting a score.

Canonical: https://elgun.si/blog/a-leakage-safe-evaluation-checklist/
Author: Elgun Hasanov
Published: 2026-09-24
Updated: 2026-10-15
Topics: evaluation, data-leakage, machine-learning

> Start with what must remain unseen. Split at that level, fit transformations inside each training fold, and keep model selection away from the final test.

The model never saw a test row during training. That sounds reassuring. But what if its scaler used the test values, its feature selection used the test labels, or another visit from the same person was already in training?

A train/test split is a boundary around information. Drawing that boundary takes a little more thought than putting rows in two folders. Think of an exam: hiding the answer sheet does not help much if the practice questions already reveal the answers.

Here is a concrete way to audit that boundary before you spend time explaining a suspiciously good score.

## First, decide what unseen means

Write down the prediction setting in one sentence. Are you predicting a new measurement from a familiar person, a new person at the same hospital, or someone from a new institution? Those are different questions, and they need different splits.

For a new-person claim, records from one person must stay together. For a future-data claim, the order in time matters. For a new-site claim, holding out random people from every site does not by itself test a completely unseen site.

A useful starting question is: **what information will actually exist when this prediction is made?** A feature measured after the outcome may be easy to include in a retrospective spreadsheet and impossible to obtain at prediction time.

Grouping is one tool for enforcing the chosen boundary. [scikit-learn's grouped cross-validation documentation](https://scikit-learn.org/stable/modules/cross_validation.html#group-k-fold) describes splits that keep a group out of both training and testing within a fold. Choosing the meaningful group remains your responsibility.

## Four fictional patients, eight records

Imagine patients A, B, C and D, each with two visits. Put every first visit in training and every second visit in testing. There are no identical rows across the two sets. Yet all four patients occur on both sides.

Now keep A and B in training, and C and D in testing. The records are still split, but the second setup also separates patient identity.

[Download the runnable split audit](https://elgun.si/blog/a-leakage-safe-evaluation-checklist/split-audit.mjs):

```sh
node split-audit.mjs
```

I ran this dependency-free example with Node 24.21.0. Its assertions passed, and it reported:

| Split | Patient IDs shared by training and test |
| --- | --- |
| First visit / second visit | A, B, C, D |
| Patients A–B / patients C–D | None |

These are synthetic identifiers. No classifier was trained, so the example does not measure how much a score would change. It demonstrates something narrower: **different rows can still represent familiar people**.

For a real dataset, add this overlap check before fitting anything. Also check duplicated content, alternate identifiers and repeated exports. A clean identifier column cannot catch duplicates that were assigned new IDs.

## Preprocessing can cross the same boundary

Suppose the training values are `[0, 2]` and the held-out value is `100`. The training mean is **1**. The mean of all three values is **34**. The same script checks both numbers.

If you center the training data using 34, the held-out observation has already influenced the fitted transformation. No test label was required for this to happen.

This is why [scikit-learn recommends learning transformations from training data only](https://scikit-learn.org/stable/common_pitfalls.html#data-leakage). A pipeline can keep fitted preprocessing inside each cross-validation fold. The fitted scaler is then applied to the held-out fold without being refitted there.

The arithmetic is an illustration of the information path, not evidence that every leaked transformation raises a score. The direction and size of any bias depend on the data and method.

In your audit, trace every operation that estimates something: imputation values, normalization parameters, selected features, dimensionality reduction and decision thresholds. Ask which records were used to choose each one.

## The final test can become part of development

Consider a quieter failure. You train correctly, inspect the final test score, change the feature set, inspect it again, and keep the version that looks best. The test set never entered `fit()`, but its results influenced your choices.

Use training data for fitting and a development procedure for choosing models and settings. Reserve the final test for the assessment you intend to report. If cross-validation is also used to estimate the performance of a tuning procedure, separate the tuning loop from the assessment loop, for example with nested cross-validation.

There is no magic protection in the word “external” either. An external cohort becomes development information if you repeatedly use its results to redesign the model. Document that change instead of continuing to call it untouched.

The same issue appears in language-model work. Choosing prompts after reading test failures is model development too. A parameter does not need to be a neural-network weight to be selected using evidence.

## A short audit before reporting

Keep the record small enough that you will actually maintain it:

| Question | Evidence to save |
| --- | --- |
| What must remain unseen? | Prediction setting and split unit |
| Can identity or content cross the split? | Group and duplicate checks |
| Where is each transformation fitted? | Training-fold pipeline and fitted settings |
| What selected the final model? | Development metric and tuning history |
| Has the test influenced another decision? | Evaluation log and any declared reuse |

Save the split IDs and code version as well as the seed. A seed alone cannot reconstruct a split after the underlying dataset changes.

These questions motivate my [ADNI–OASIS cross-cohort research](https://elgun.si/#hasanov2026asymmetric): make the evaluation design visible alongside the model. The related post on [meeting a new dataset](https://elgun.si/blog/when-a-model-meets-a-new-dataset/) takes the next step: even with a clean boundary, the population itself can change.

Before your next training run, try one cheap check: print the intersection of the group IDs on both sides. An empty result will not prove the entire experiment is sound, but a nonempty result can expose a problem immediately.

Prepared with AI assistance. Sources and a worked example are provided so you can check the reasoning.
