0

I have a CNN model for 4 output classes. I want to create a confusion matrix between the real labels and the predicted ones, but when the function is called it throws me this error:

Classification metrics can't handle a mix of multiclass and multilabel-indicator targets

Currently I am using the following code to accomplish this task:

datagen_test = ImageDataGenerator(..).flow_from_directory(...,batch_size = 32)

test_predictions_baseline = model.predict(data_gen_pruebas, batch_size=32)

def plot_cm(labels, predictions, p=0.5):
  cm = confusion_matrix(labels, predictions > p)
  plt.figure(figsize=(5,5))
  sns.heatmap(cm, annot=True, fmt="d")
  plt.title('Confusion matrix @{:.2f}'.format(p))
  plt.ylabel('Actual label')
  plt.xlabel('Predicted label')

  print('Legitimate Transactions Detected (True Negatives): ', cm[0][0])
  print('Legitimate Transactions Incorrectly Detected (False Positives): ', cm[0][1])
  print('Fraudulent Transactions Missed (False Negatives): ', cm[1][0])
  print('Fraudulent Transactions Detected (True Positives): ', cm[1][1])
  print('Total Fraudulent Transactions: ', np.sum(cm[1]))

plot_cm(datagen_test .labels, test_predictions_baseline)

How can i solve this problem?

desertnaut
  • 57,590
  • 26
  • 140
  • 166

0 Answers0