The size of double_coef_ in the screenshot. SVC

In SVC()for multi-classification, one-vs-one classifiers are classified. Thus, there must be classifiers n_class * (n_class - 1)/2. But why clf.dual_coef_only returns me (n_class - 1) * n_SV? What is each line?

+3
source share
1 answer

The double coefficients sklearn.svm.SVC in setting up multiclasses are difficult to interpret. The scikit-learn documentation has an explanation. Sklearn.svm.SVC uses libsvm for calculations and uses the same data structure for double coefficients. Another explanation of the organization of these coefficients is in the FAQ . In the case of the coefficients that you find in the installed SVC classifier, the interpretation is as follows:

Supported vectors identified by SVC belong to a specific class. In double coefficients, they are ordered according to the class to which they belong. Given an established SVC rating, e.g.

from sklearn.svm import SVC
svc = SVC()
svc.fit(X, y)

you will find

svc.classes_   # represents the unique classes
svc.n_support_ # represents the number of support vectors per class

. , , n_classes-1 --, . , vs-one.

support_indices = np.cumsum(svc.n_support_)
svc.dual_coef_[0:support_indices[0]]  # < ---
                                      # weights on support vectors of class 0
                                      # for problems 0v1, 0v2, ..., 0v(n-1)
                                      # so n-1 columns for each of the 
                                      # svc.n_support_[0] support vectors
svc.dual_coef_[support_indices[1]:support_indices[2]]  
                                      #  ^^^
                                      # weights on support vectors of class 1
                                      # for problems 0v1, 1v2, ..., 1v(n-1)
                                      # so n-1 columns for each of the 
                                      # svc.n_support_[1] support vectors
...
svc.dual_coef_[support_indices[n_classes - 2]:support_indices[n_classes - 1]]
                                      #  ^^^
                                      # weights on support vectors of class n-1
                                      # for problems 0vs(n-1), 1vs(n-1), ..., (n-2)v(n-1)
                                      # so n-1 columns for each of the 
                                      # svc.n_support_[-1] support vectors

0, 1,..., n-1 vs-one. , , n_classes - 1 . , , , . , .

, , , , , "" . .

from sklearn.svm import SVC
svc = SVC(kernel="linear")
svc.fit(X, y)  # X is your data, y your labels

svc.coef_

((n_class * (n_class -1)/2), n_features) .

doc :

class 0 vs class 1
class 0 vs class 2
...
class 0 vs class n-1
class 1 vs class 2
class 1 vs class 3
...
...
class n-2 vs class n-1
+6

Source: https://habr.com/ru/post/1538967/


All Articles