How to apply standardization to SVMs in scikit-learn? How to apply standardization to SVMs in scikit-learn? python python

How to apply standardization to SVMs in scikit-learn?


Neither.

scaler.transform(X_train) doesn't have any effect. The transform operation is not in-place.You have to do

X_train = scaler.fit_transform(X_train)X_test = scaler.transform(X_test)

or

X_train = scaler.fit(X_train).transform(X_train)

You always need to do the same preprocessing on both training or test data. And yes, standardization is always good if it reflects your believe for the data.In particular for kernel-svms it is often crucial.


Why not use a Pipeline to chain (or combine) transformers and estimators in one go? Saves you the hassle of separately fitting and transforming your data and then using the estimator. It would save some space, too.

from sklearn.pipeline import Pipelinepipe_lrSVC = Pipeline([('scaler', StandardScaler()), ('clf', LinearSVC())])pipe_lrSVC.fit(X_train, y_train)y_pred = pipe_lrSVC.predict(X_test)