1. Home
  2. Data Science
  3. Scikit-learn
  4. Why is scaler.fit_transform(X_train) followed by…

Added 30 Nov -0001

Why is scaler.fit_transform(X_train) followed by scaler.transform(X_test) correct, while scaler.fit_transform(X_test) is not?

  1. The scaler requires the test set to be a subset of the training rows it was fitted on
  2. Fitting on the test set leaks its statistics into preprocessing and inflates scores Correct answer
  3. transform must be called before fit on the training set to establish the column order
  4. fit_transform on the test set is slower, yet returns an identical result

Correct answer

B. Fitting on the test set leaks its statistics into preprocessing and inflates scores

17 views

MCQSEXAM

Explanation

Data leakage occurs when preprocessing statistics such as the mean and standard deviation are computed from the test set, because the model then indirectly sees information it should not have at prediction time. fit computes those statistics and transform applies them, so only the training set may be fitted. Inside cross-validation a Pipeline repeats this automatically for each fold.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? 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