Scaling Data In Scikit-learn SVM
While libsvm provides tools for scaling data, with Scikit-Learn (which should be based upon libSVM for the SVC classifier) I find no way to scale my data. Basically I want to use
Solution 1:
You have that functionality in sklearn.preprocessing
:
>>> from sklearn import preprocessing
>>> X = [[ 1., -1., 2.],
... [ 2., 0., 0.],
... [ 0., 1., -1.]]
>>> X_scaled = preprocessing.scale(X)
>>> X_scaled
array([[ 0. ..., -1.22..., 1.33...],
[ 1.22..., 0. ..., -0.26...],
[-1.22..., 1.22..., -1.06...]])
The data will then have zero mean and unit variance.
Solution 2:
You can also try StandardScaler
for datascaling :
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(Xtrain) # where X is your data to be scaled
Xtrain = scaler.transform(Xtrain)
Post a Comment for "Scaling Data In Scikit-learn SVM"