Why should resampling happen only at fit time and not at prediction time in an ML pipeline?

Last updated 15 November 2026

  • Resampling shapes what the model learns. At inference every real input must be scored exactly once, so dropping rows or inventing fake ones corrupts predictions and evaluation.

  • In cross-validation, resample only inside each training fold. Resampling before splitting leaks synthetic neighbors of validation points into training.

  • imbalanced-learn samplers use fit_resample, and imblearn.pipeline.Pipeline applies them during fit but skips them in predict and score.

  • https://imbalanced-learn.org/stable/common_pitfalls.html
  • https://blog.trainindata.com/undersampling-techniques-for-imbalanced-data/
  • https://imbalanced-learn.org/stable/references/generated/imblearn.pipeline.Pipeline.html
All Imbalanced Datasets interview questions