1. Home
  2. Data Science
  3. Scikit-learn
  4. Why does putting StandardScaler and a classifier inside…

Added 30 Nov -0001

Why does putting StandardScaler and a classifier inside Pipeline prevent leakage during cross_val_score?

  1. Pipeline refits the scaler on every validation fold to check stability across the splits
  2. The pipeline scales the whole dataset once before splitting, which is equivalent and faster
  3. During each fold, fit runs on the training part only and transform is applied to the held-out part Correct answer
  4. Pipeline disables scaling during cross-validation entirely, so the scaler only runs on the final fit

Correct answer

C. During each fold, fit runs on the training part only and transform is applied to the held-out part

16 views

MCQSEXAM

Explanation

Pipeline treats preprocessing and estimation as one estimator, so during cross-validation each fold's fit sees only that fold's training rows while held-out rows are merely transformed. This reproduces the deployment situation, where new data must be transformed with statistics learned from training data. Pipelines also make grid search over preprocessing parameters straightforward.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Scikit-learn MCQs

Practise all Scikit-learn MCQs

Similar MCQs