Issue
I'm not able to get the support vectors out of a OneVsRest or OneVsOne Classifier in Python.
The code looks like this but the classifiers don't seem to have a support vector attribute. The normal SVC model has them, so my question is: is there any way to get them out of the classifier?
model_linear = svm.SVC(kernel="linear")
or_linear = OneVsRestClassifier(model_linear)
clf_or_linear = or_linear.fit(X_train, y_train)
print(or_linear.support_vectors_)
oo_linear = OneVsOneClassifier(model_linear)
clf_oo_linear = oo_linear.fit(X_train, y_train)
print(oo_linear.support_vectors_)
Thanks for any help:-)
Solution
The or_linear is an array of SVC estimators.
if you print
print(or_linear.estimators_)
you will get:
[SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear'), SVC(kernel='linear')]
You can loop over every SVC to get every support vector like this
for svc in or_linear.estimators_:
print(svc.support_vectors_)
Answered By - dotheM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.