1. Home
  2. Data Science
  3. Scikit-learn
  4. Why should a scaler be fit_transform on the training set…

Added 30 Nov -0001

Why should a scaler be fit_transform on the training set but only transform the test set?

  1. fit_transform returns a sparse matrix while transform does not
  2. Fitting twice causes the scaler to forget its parameters
  3. Fitting on test data leaks its statistics into training Correct answer
  4. transform is the only method that accepts two arguments

Correct answer

C. Fitting on test data leaks its statistics into training

16 views

MCQSEXAM

Explanation

Calling fit on the test set would compute the mean and standard deviation from data the model is supposed to be evaluated on, leaking information and inflating test scores. The correct sequence learns the parameters on training data once and applies that same mapping with transform to validation and test data. This is the most common example of data leakage, and it is why preprocessing belongs inside a Pipeline.

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