Why does putting StandardScaler and a classifier inside Pipeline prevent leakage during cross_val_score?
Correct answer
C. During each fold, fit runs on the training part only and transform is applied to the held-out part
16 views
C. During each fold, fit runs on the training part only and transform is applied to the held-out part
16 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.