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

Quick Overview

Explain why undersampling, oversampling and SMOTE belong only in the training step of an ML pipeline. Tests understanding of samplers versus row-wise transformers, leakage in cross-validation, distorted test metrics on imbalanced data, and how resampling shifts predicted probabilities.

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

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Why should resampling happen only at fit time and not at prediction time in an ML pipeline? Resampling here means undersampling, random oversampling or synthetic methods such as SMOTE, used to handle an imbalanced target. ```hint Compare a scaler with a sampler A scaler maps each row to one new row. What does an undersampler or SMOTE do to the set of rows, and what would that mean for a batch of real requests or a labeled test set? ``` ### What a Strong Answer Covers - How samplers differ from row-wise transformers such as scalers and encoders - What would break if resampling ran on serving traffic or on the test set - Where resampling belongs in cross-validation, and why resampling before the split leaks - How the tooling enforces fit-only resampling - What training-time resampling does to the predicted probabilities ### Follow-up Questions - A model trained on SMOTE-balanced data outputs probabilities, but the real positive rate is 1%. How do you get calibrated probabilities? - Should the scaler come before or after SMOTE in the pipeline? Why? - When would class weights be a better choice than resampling? - How would you evaluate a fraud model so the reported precision matches what production will see?

Overview: Explain why undersampling, oversampling and SMOTE belong only in the training step of an ML pipeline. Tests understanding of samplers versus row-wise transformers, leakage in cross-validation, distorted test metrics on imbalanced data, and how resampling shifts predicted probabilities.

PracHub logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

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

Resampling here means undersampling, random oversampling or synthetic methods such as SMOTE, used to handle an imbalanced target.

What a Strong Answer Covers Guidance

  • How samplers differ from row-wise transformers such as scalers and encoders
  • What would break if resampling ran on serving traffic or on the test set
  • Where resampling belongs in cross-validation, and why resampling before the split leaks
  • How the tooling enforces fit-only resampling
  • What training-time resampling does to the predicted probabilities

Follow-up Questions Guidance

  • A model trained on SMOTE-balanced data outputs probabilities, but the real positive rate is 1%. How do you get calibrated probabilities?
  • Should the scaler come before or after SMOTE in the pipeline? Why?
  • When would class weights be a better choice than resampling?
  • How would you evaluate a fraud model so the reported precision matches what production will see?