Fit Once, Scale Twice

You're building a preprocessing pipeline with a StandardScaler before a classifier and splitting data into train and test sets. Which approach avoids data leakage?

A

Fit the scaler on the test set only, then apply it to the training set

B

Fit the scaler on the training set only, then use those fitted parameters to transform both train and test sets

C

Fit the scaler on the full dataset (train + test combined), then split into train and test

D

Fit a separate scaler on the test set so its distribution is scaled correctly