I have trained my multiclass SVM model for MNIST classification in Python using scikit-learn using the following code:

from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV

parameters = {'kernel':['rbf'], 
              'C':[1, 10, 100, 1000],
              'gamma':[1e-3, 1e-4]}
clf = GridSearchCV(SVC(), parameters)
clf.fit(xtrain, y_train)

 svmclf = clf.best_estimator_
 svmclf.fit(xtrain, y_train)

I wanted to get some parameters of the trained SVM: support vectors, alpha values and bias. So I tried this:

SVs= clf.best_estimator_.support_vectors_
Alpha= clf.best_estimator_._dual_coef_

I checked the shape of these parameters and it gives me this, I don't know if is this correct?

print (SVs.shape)  
(486, 2048)
print (Alpha.shape)
(9, 486)
print (bias.shape)

Also, how could I save each of these parameters in a file with readable format?

I tried this script :

import numpy
np.savetxt('values.csv', sv, fmt="%d", delimiter=",")

But the stored data was like this format



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy