scikit-learn 在 multi-class classification 中默认使用 One-Vs-Rest 吗?

Does scikit-learn use One-Vs-Rest by default in multi-class classification?

我正在处理一个多 class 问题(4 classes),我正试图在 Python.

中使用 scikit-learn 解决它

我看到我有三个选择:

  1. 我简单地实例化了一个classifier,然后我用train拟合并用test求值;

    classifier = sv.LinearSVC(random_state=123)
    classifier.fit(Xtrain, ytrain)
    classifier.score(Xtest, ytest)
    
  2. I "encapsulate" OneVsRest 对象中的实例化 classifier,生成一个新的 classifier 我用于训练和测试;

    classifier = OneVsRestClassifier(svm.LinearSVC(random_state=123))
    classifier.fit(Xtrain, ytrain)
    classifier.score(Xtest, ytest)
    
  3. I "encapsulate" OneVsOne 对象中的实例化 classifier,生成一个新的 classifier 我用于训练和测试。

    classifier = OneVsOneClassifier(svm.LinearSVC(random_state=123))
    classifier.fit(Xtrain, ytrain)
    classifier.score(Xtest, ytest)
    

我了解 OneVsRest 和 OneVsOne 之间的区别,但我无法理解在第一种情况下我在做什么,因为我没有明确选择这两个选项中的任何一个。在这种情况下,scikit-learn 会做什么?它是否隐式使用 OneVsRest?

如能对此事作出任何澄清,我们将不胜感激。

最好的, 先生

编辑: 澄清一下,我对 SVM 的情况并不特别感兴趣。例如,RandomForest 呢?

更新的答案:正如评论和编辑中所阐明的,问题更多是关于 sklearn 的一般设置,而不是关于 LinearSVC 的具体情况解释如下。

这里的主要区别是您可以使用的一些分类器具有 "built-in multiclass classification support",即默认情况下该算法可以区分两个以上 类 。例如,随机森林或具有多个输出节点的多层感知器 (MLP) 就是一个例子。

在这些情况下,根本不需要 OneVs 对象,因为您已经在解决您的任务。事实上,使用这样的策略甚至可能会降低你的表现,因为你是 "hiding" 算法的潜在相关性,让它只在单个二进制实例之间做出决定。

另一方面,像SVCLinearSVC这样的算法只支持二进制分类。因此,为了扩展这些 类 的(性能良好的)算法,我们不得不依赖于从我们最初的多类分类任务减少到二元分类任务。

据我所知,最完整的概述可以找到here: 如果向下滚动一点,您可以看到哪一种算法本质上是多类的,或者默认使用其中一种策略。
请注意,OVO 下列出的所有算法实际上现在都默认采用 OVR 策略!在这方面,这似乎是稍微过时的信息。

初步回答:

这个问题很容易通过查看 the relevant scikit-learn documentation 来回答。
通常,对 Whosebug 的期望是您至少自己进行了某种形式的研究,因此请考虑先查看现有文档。

multi_class : string, ‘ovr’ or ‘crammer_singer’ (default=’ovr’)

Determines the multi-class strategy if y contains more than two classes. "ovr" trains n_classes one-vs-rest classifiers, while "crammer_singer" optimizes a joint objective over all classes. While crammer_singer is interesting from a theoretical perspective as it is consistent, it is seldom used in practice as it rarely leads to better accuracy and is more expensive to compute. If "crammer_singer" is chosen, the options loss, penalty and dual will be ignored.

所以,很明显,它使用一对多。

"regular" SVC.

也是如此