Suppose an agent-generated PR describes a preprocessing refactor as a no-op. The review question: were all stateful transforms fitted only on training data? Scikit-learn says split first, fit preprocessing on training data, then apply it to test. Fitting a scaler, imputer, encoder, or feature selector on held-out rows leaks information about those rows (docs).
This is proposed review practice, not a verdict on every PR.
Steps
- Locate the train/test split or CV splitter in the changed files.
- List every fit, fit_transform, or partial_fit call; any stateful call above the split is a candidate leak.
- Check scalers, imputers, encoders, feature selectors, resamplers, and pipelines fitted outside the training branch.
- For cross-validation, verify preprocessing is fitted inside each training fold. GroupKFold keeps a group in a test fold absent from that fold's training data, but a group split alone does not certify performance (scikit-learn CV docs).
- If ordering is wrong, move the fit into the training branch; keep only a sound refactor.
Test
Use a small synthetic table with a known split and a deliberate distribution shift in one column. Identify the pipeline's learned preprocessing state: a scaler's center and scale, an imputer's fill value, or an encoder's categories. Compare it with two references: fitted on training rows only and fitted on all rows. Choose a fixture where those two reference states actually differ. Expect the reviewed state to match training-only. A match with all-rows is evidence to inspect which rows reached the fit operation and when. Correct any verified leakage and rerun the same check. If it matches training-only but metrics look implausibly strong, inspect target construction, duplicate rows, and feature timing; this probe does not prove model quality.
Boundaries
Stateless transforms, transductive setups, and leakage-free splits need different checks; state which applies. The NIST playbook offers actions by Core outcome that teams select for their context (NIST AI RMF Playbook). A review record is local evidence, not a compliance claim.
This article was created with AI assistance.
Top comments (0)