如何将OneVsRestClassifier与SVC一起用于多标签问题?

时间:2013-05-06 15:38:37

标签: svm scikit-learn

我正在使用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>

有人知道它是什么吗?

1 个答案:

答案 0 :(得分:5)

这是bugOneVsRestClassifier在找到predict_proba方法时调用SVC方法,但probability=True上的方法实际上不起作用,除非您使用LinearSVC构建predict_proba来获取decision_function({1}}我实际上并不鼓励。)

它适用于{{1}}的原因是该类没有{{1}},因此OvR退回到{{1}}方法。