0

This my code for drawing ROC Curve on my notebook. But I don't understand the error, sorry im newbie.. I have a problem with ValueError: multiclass format is not supported. I'm already looking sci-kit learn but it doesn't help. In the end, I'm still have ValueError: multiclass format is not supported.

from sklearn.metrics import roc_curve
from sklearn.metrics import auc

# calculate the fpr and tpr for all thresholds of the classification
probs = model_naive.predict_proba(X_test)
preds = probs[:,1]
fpr, tpr, threshold = roc_curve(y_test, preds)
roc_auc = auc(fpr, tpr)
plt.figure(dpi=600)                       # to plot high quality graph
plt.title('Receiver Operating Characteristic')
plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)
plt.legend(loc = 'lower right')
plt.plot([0, 1], [0, 1],'r--')
plt.ylabel('True Positive Rate', color='g')
plt.xlabel('False Positive Rate', color='r')
plt.savefig("assets/ROC_curve.png")
plt.show()

and this is the error I got:

ValueError                                Traceback (most recent call last)
<ipython-input-83-620bd2e4aa8a> in <module>()
      5 probs = model_naive.predict_proba(X_test)
      6 preds = probs[:,1]
----> 7 fpr, tpr, threshold = roc_curve(y_test, preds)
      8 roc_auc = auc(fpr, tpr)
      9 plt.figure(dpi=600)                       # to plot high quality graph

1 frames
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_ranking.py in _binary_clf_curve(y_true, y_score, pos_label, sample_weight)
    534     if not (y_type == "binary" or
    535             (y_type == "multiclass" and pos_label is not None)):
--> 536         raise ValueError("{0} format is not supported".format(y_type))
    537 
    538     check_consistent_length(y_true, y_score, sample_weight)

ValueError: multiclass format is not supported

Any help is appreciated

divaniaf
  • 13
  • 4
  • 2
    roc_curve is for binary_classifiers i.e for example either 1 or 0. if you are working on multiclass, then you can predict one class at a time and then run roc on it or you have to find other metrics like confusion matrix. – simpleApp Jun 12 '21 at 10:51
  • https://stackoverflow.com/a/61115110/9977321 – Sina Jun 12 '21 at 10:52

0 Answers0