MEric
MEric

Reputation: 966

No Support Vector Attribute

The project I am currently working on makes use of the sklearn svm.SVC class where at one point in the code instantiate the following:

self.classifier = OneVsRestClassifier(SVC(kernel = 'linear', probability = True))

After fitting the classifier, I then try to inspect the support_vector_ or support_ attributes of the classifier. However, I get the following error:

'SVC' object has no attribute 'support_vectors_'

I tried changing the kernel to 'poly' or 'rbf', but this does not fix the error. Why is this happening? Shouldn't any linear SVM have something (i.e. 'None' at the least) for this attribute? I am using sklearn version 0.15.1 if that helps.

Thanks!

Upvotes: 0

Views: 1229

Answers (1)

eickenberg
eickenberg

Reputation: 14377

Assuming you obtained the error message by trying to evaluate

self.classifier.estimator.support_vectors_

observe that OneVsRestClassifier clones your estimator as many times as there are classes and fits as many of them to your data. They can be found in the estimators_ variable of the ovr. Try

self.classifier.estimators_[0].support_vectors_

That will give you the support vectors for the first OVR problem.

Upvotes: 1

Related Questions