Linked Questions

Popular Questions

too many indices array when draw Roc curve for keras model

Asked by At

I want to classify images it is about 7 classifier and i want to plot the ROC curve to measure the performance of the model

it is unbalanced so i try to balanced the train set by used data augmentation and i want to measures the performance by several tool

enter code here


fpr = dict()
tpr = dict()
roc_auc = dict()
for i in range(num_classes):
  fpr[i], tpr[i], _ = roc_curve(y_test[:, i], pred_test[:,i])
  roc_auc[i] = auc(fpr[i], tpr[i])

# Plot of a ROC curve for a specific class
for i in range(num_classes):
  plt.figure()
  plt.plot(fpr[i], tpr[i], label='ROC curve (area = %0.2f)' % roc_auc[i])
  plt.plot([0, 1], [0, 1], 'k--')
  plt.xlim([0.0, 1.0])
  plt.ylim([0.0, 1.05])
  plt.xlabel('False Positive Rate')
  plt.ylabel('True Positive Rate')
  plt.title('Receiver operating characteristic example')
  plt.legend(loc="lower right")
  plt.show()


 ---------------------------------------------------------------------------
 IndexError                                Traceback (most recent call last)
 <ipython-input-51-b620aaf312da> in <module>
  8 roc_auc = dict()
  9 for i in range(num_classes):
---> 10     fpr[i], tpr[i], _ = roc_curve(y_test[:, i], pred_test[:,i])
 11     roc_auc[i] = auc(fpr[i], tpr[i])
 12 

 IndexError: too many indices for array

the error show too many indices y_test.shape give me (1103, 7) pred_test.shape give me (1103,) how can i solve this problem to draw Roc curve for each class

Related Questions