You should scale your features before applying PCA. Using PCA we would like to get components which maximizes the variance. Depending on your features the feature scales might mislead the PCA and thus yielding to “wrong” components (e.g. distance in kilometers vs. humidity in %). You shouldn’t fit a teachable method on all datasets.


The first approach is right. You fit the scaler on the training set and transform the dev and test set. The dev error is an approximation of the final test error, so you should transform both sets identically. During your model training you can estimate the error on the dev set and e.g. perform early stopping based on this error. The test error is only calculated once your model is ready.