You should apply StandardScaler after train_test_split and fit it only on the training data. If you scale before splitting, the scaler learns the mean and standard deviation from the entire dataset — including the test set — which leaks information about unseen data and can make validation results unrealistically good. Fitting the scaler only on X_train ensures that scaling parameters reflect the same data distribution the model learns from, and applying that scaler to both X_train and X_test preserves a realistic, generalizable evaluation.