Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between OneVsRestClassifier with SVC and SVC with decision_function_shape='ovr'?

I thought it should be the same, but for method decision_function() I get different results. And SVC with only decision_function_shape='ovr' is really faster.

Related: Scikit learn multi-class classification for support vector machines

like image 934
MBrzeski Avatar asked Sep 20 '16 22:09

MBrzeski


People also ask

What is the difference between SVC and linear SVC?

The main difference between them is linearsvc lets your choose only linear classifier whereas svc let yo choose from a variety of non-linear classifiers. however it is not recommended to use svc for non-linear problems as they are super slow.

What is Decision_function_shape in svm?

To provide a consistent interface with other classifiers, the decision_function_shape option allows to aggregate the results of the “one-against-one” classifiers to a decision function of shape (n_samples, n_classes) >>> X = [[0], [1], [2], [3]] >>> Y = [0, 1, 2, 3] >>> clf = svm.SVC(decision_function_shape='ovo') >>> ...

What is the difference between SVC and svm?

The limitation of SVC is compensated by SVM non-linearly. And that's the difference between SVM and SVC. If the hyperplane classifies the dataset linearly then the algorithm we call it as SVC and the algorithm that separates the dataset by non-linear approach then we call it as SVM.

What does SVC mean in Python?

The objective of a Linear SVC (Support Vector Classifier) is to fit to the data you provide, returning a "best fit" hyperplane that divides, or categorizes, your data.


1 Answers

I got some clarification on the documentation of LinearSVC in the See also heading, where SVC is mentioned.

SVC

Implementation of Support Vector Machine classifier using libsvm:

....

....

Furthermore SVC multi-class mode is implemented using one vs one scheme while LinearSVC uses one vs the rest. It is possible to implement one vs the rest with SVC by using the sklearn.multiclass.OneVsRestClassifier wrapper.

....

Also, SVC delegates all the training to the underlying libsvm library, which handles the multi-class case as 'OvO' (even if the decision_function_shape = 'ovr').

Its mentioned in the issue @delusionX mentioned that decision_function_shape is just for compatibility with scikit API. Its most probably, that all other estimators handle the multi-class as OvR and so when SVC is used in combination with other things, (Like for example in a Pipeline, GridSearchCV, Or wrappers like OneVsRestClassifier) returning a OvO decision function breaks the working of others. But I could not find that written explicitly anywhere.

Fun fact: OneVsOneClassifier also returns a decision function which confirms with the shape of OvR.

like image 76
Vivek Kumar Avatar answered Nov 15 '22 18:11

Vivek Kumar