The idea is that your scale the values take in consideration only the X_train because it's the only data you have to train the model. Test data is only used to simulated when you are applying your model to real live.
As you know, StandarScaler depend on the data, so the scalation would be different between train and test data. What you do fiting X_train is that all the test data will be transformed following the parameters you obtained on the train set.
Clear example:
Now imagine you have only 1 samples test. Do you fit and transform this simple test data? (difficult for only one sample). The answer is NO. You use the parameters of X_train to scale this unique value.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…