Skip to content Skip to sidebar Skip to footer

Scikit-learn Gridsearch Giving "valueerror: Multiclass Format Is Not Supported" Error

I'm trying to use GridSearch for parameter estimation of LinearSVC() as follows - clf_SVM = LinearSVC() params = { 'C': [0.5, 1.0, 1.5], 'tol': [1e-3, 1e-4, 1e-

Solution 1:

Remove scoring='roc_auc' and it will work as roc_auc curve does not support categorical data.

Solution 2:

from:

http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score

"Note: this implementation is restricted to the binary classification task or multilabel classification task in label indicator format."

try:

from sklearn importpreprocessingy= preprocessing.label_binarize(y, classes=[0, 1, 2, 3])

before you train. this will perform a "one-hot" encoding of your y.

Solution 3:

As it has been pointed out, you must first binarize y

y = label_binarize(y, classes=[0, 1, 2, 3])

and then use a multiclass learning algorithm like OneVsRestClassifier or OneVsOneClassifier. For example:

clf_SVM = OneVsRestClassifier(LinearSVC())
params = {
      'estimator__C': [0.5, 1.0, 1.5],
      'estimator__tol': [1e-3, 1e-4, 1e-5],
      }
gs = GridSearchCV(clf_SVM, params, cv=5, scoring='roc_auc')
gs.fit(corpus1, y)

Solution 4:

You can directly use to_categorical rather than preprocessing.label_binarize() depending on your problem. The problem is actually from using scoring=roc_auc. Note that roc_auc does not support categorical data.

Post a Comment for "Scikit-learn Gridsearch Giving "valueerror: Multiclass Format Is Not Supported" Error"