【问题标题】:Order of class in n_support_ (sklearn svm)n_support_ 中的类顺序(sklearn svm)
【发布时间】:2019-02-28 13:36:05
【问题描述】:

sklearn SVM SVC documentation 中,我试图弄清楚 n_support_ 属性以什么顺序给出支持向量的数量。我找不到任何地方提到它。拜托,谁能告诉我如何找到它?

示例:用于类 -1,+1 的二元分类

In []: print (svm_fit.n_support_)
Out[]: [6388 6383]

现在我不确定第一个值属于哪个类。

【问题讨论】:

    标签: python scikit-learn svm libsvm


    【解决方案1】:

    documentation中提供的示例稍作修改:

    import numpy as np
    X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
    y = np.array([-1, -1, 1, 1])
    from sklearn.svm import SVC
    clf = SVC()
    clf.fit(X, y)
    print(f'Number of support vectors in each class: {clf.n_support_}')
    print(f'Classes: {clf.classes_}')
    

    您可以通过调用.classes_来访问分类器的类。

    上面的代码打印出来:

    每个类的支持向量个数:[2 2]

    类:[-1 1]

    表示2属于-1类,2属于1类。

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 2018-09-25
      • 2017-04-21
      • 2018-08-11
      • 2014-10-10
      • 2020-05-14
      • 2018-06-24
      • 2018-08-06
      • 1970-01-01
      相关资源
      最近更新 更多