Error with sklearn CalibratedClassifierCV and SVM

I want to use sklearn CalibratedClassifierCV in combination with SVL sklearn to make predictions for a multiclass problem (9 classes). However, when I run it, I get the following error. The same code will not work with another model (such as 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

      

+3


source to share


1 answer


This is an SVC problem using the One-vs-One strategy, and so the decisive function has a form (n_samples, n_classes * (n_classes - 1) / 2)

. A possible workaround will be done for CallibratedClassifierCV(OneVsRestClassifier(SVC()))

. If you want to use sigmoidal calibration, you can also do SVC(probability=True)

and not use CallibratedClassifierCV

.



We have to fix the SVC solution function I think.

+4


source







All Articles