3

我正在使用 OneVsRestClassifier 进行多标签分类。它适用于 LinearSVC,但是当我将其应用于 SVC 时,会出现以下错误:

classifier = OneVsRestClassifier(SVC(class_weight='balanced'))
classifier.fit(X1, y1)
y2 = classifier.predict(X2)

Traceback (most recent call last):
...
File "/usr/local/lib/python2.7/dist-packages/sklearn/multiclass.py", line 219, in predict
  return predict_ovr(self.estimators_, self.label_binarizer_, X)
File "/usr/local/lib/python2.7/dist-packages/sklearn/multiclass.py", line 93, in predict_ovr
  Y = np.array([_predict_binary(e, X) for e in estimators])
File "/usr/local/lib/python2.7/dist-packages/sklearn/multiclass.py", line 66, in _predict_binary
  score = estimator.predict_proba(X)[:, 1]
File "/usr/local/lib/python2.7/dist-packages/sklearn/svm/base.py", line 490, in predict_proba
  "probability estimates must be enabled to use this method")
NotImplementedError: probability estimates must be enabled to use this method</code>

有人知道它是什么吗?

4

1 回答 1

5

这是一个错误。找到一个时OneVsRestClassifier调用该方法,但该方法实际上不起作用,除非您使用它构建它以获得Platt 缩放(我实际上并不鼓励)。predict_probaSVCprobability=True

它起作用的原因LinearSVC是该类没有predict_proba,因此 OvR 退回到该decision_function方法。

于 2013-05-07T14:11:46.783 回答