Why is scaler.fit_transform(X_train) followed by scaler.transform(X_test) correct, while scaler.fit_transform(X_test) is not?
Correct answer
B. Fitting on the test set leaks its statistics into preprocessing and inflates scores
17 views
B. Fitting on the test set leaks its statistics into preprocessing and inflates scores
17 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.