rescale the training data x_train_scaled scaler transform(x_trainsvm svc(learn an svm on the scaled training data svm fit(x_train_scaledy_trainscale the test data and score the scaled data x_test_scaled scaler transform(x_testprint("test score{ }format(svm score(x_test_scaledy_test))out[ ]test score parameter selection with preprocessing now let' say we want to find better parameters for svc using gridsearchcvas discussed in how should we go about doing thisa naive approach might look like thisin[ ]from sklearn model_selection import gridsearchcv for illustration purposes onlydon' use this codeparam_grid {' '[ ]'gamma'[ ]grid gridsearchcv(svc()param_grid=param_gridcv= grid fit(x_train_scaledy_trainprint("best cross-validation accuracy{ }format(grid best_score_)print("best set score{ }format(grid score(x_test_scaledy_test))print("best parameters"grid best_params_out[ ]best cross-validation accuracy best set score best parameters{'gamma' ' ' herewe ran the grid search over the parameters of svc using the scaled data howeverthere is subtle catch in what we just did when scaling the datawe used all the data in the training set to find out how to train it we then use the scaled training data to run our grid search using cross-validation for each split in the cross-validationsome part of the original training set will be declared the training part of the splitand some the test part of the split the test part is used to measure what new data will look like to model trained on the training part howeverwe already used the information contained in the test part of the splitwhen scaling the data remember that the test part in each split in the cross-validation is part of the training setand we used the information from the entire training set to find the right scaling of the data algorithm chains and pipelines