sklearn CalibratedClassifierCV和SVM出错

时间:2015-04-26 05:05:41

标签: python machine-learning scikit-learn svm

我想将sklearn的CalibratedClassifierCV与sklearn的SVC结合使用来预测多类(9类)预测问题。但是当我运行它时,我收到以下错误。相同的代码对于不同的模型(即RandomForestCalssifier)没有问题。

kf = StratifiedShuffleSplit(y, n_iter=1, test_size=0.2)
clf = svm.SVC(C=1,probability=True)            
sig_clf = CalibratedClassifierCV(clf, method="isotonic", cv=kf)
sig_clf.fit(X, y)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/calibration.py", line 166, in fit
    calibrated_classifier.fit(X[test], y[test])
  File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/calibration.py", line 309, in fit
    calibrator.fit(this_df, Y[:, k], sample_weight)
IndexError: index 9 is out of bounds for axis 1 with size 9

1 个答案:

答案 0 :(得分:4)

这是SVC使用One-vs-One策略的问题,因此决策函数具有形状On Error GoTo errhandle 'Your If is missing here. Me.Filter = "CurrentDate= #" & Format(Me!CurrentDate, "yyyy\-mm\-dd") & "# and DiscoverTime= '" & _ Me!DiscoverTime & "' and TailNumber= '" & Me!TailNumber & "' and FleetID= '" & Me!FleetID & "'" Me.FilterOn = True DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "some.email@domain.com", "", "", "Recovery Report", "Attached is the submitted Recovery Report" DoCmd.Close acForm, "frmETIC", acSaveNo DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal End If exitErr: Exit Sub errhandle: If Err.Number = 2501 Then MsgBox ("Email Cancelled") DoCmd.Close acForm, "frmETIC", acSaveNo DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal Else MsgBox "Error (" & Err.Number & ") - " & Err.Description & " Occurred." End If Resume exitErr 。 可能的解决方法是(n_samples, n_classes * (n_classes - 1) / 2)。 如果您想使用S形校准,您也可以CallibratedClassifierCV(OneVsRestClassifier(SVC()))而不是SVC(probability=True)

我认为我们应该修正SVC决策功能。