Skip to content
ML Academy

Classical ML, validation, metrics, interpretation, debugging · insight-0152

Resample inside the cross-validation pipeline so validation folds keep the real class mix

Evidence type
documented fact
Difficulty
easy
Roles
Data scientist, ML engineer
Industries
cross-industry

Summary: situation, action, reason, boundary

  1. Situation

    You undersample or oversample the whole dataset, then cross-validate or split into train and test.

  2. Action

    Use an imbalanced-learn Pipeline (sampler then estimator) so resampling runs only during fit on each training fold, and evaluate on untouched folds.

  3. Reason

    Evaluation must reflect the population the model will meet, which includes its real prevalence and no duplicated rows.

  4. Boundary

    Any resampling: random over/undersampling, SMOTE variants, cleaning methods such as Tomek links.

Symptom or risk

Test folds are balanced artificially and may contain copies or synthetic neighbours of training rows; scores do not match deployment.

Exceptions

None for evaluation; resampling the test data is never representative of deployment.

Trade-offs

Pipelines add a dependency on imbalanced-learn but remove a whole class of leakage bugs.

Pitfalls

Using scikit-learn's Pipeline with a sampler step, which does not support samplers; use the imbalanced-learn Pipeline.

Lessons and concepts

Claims and their sources