Question

I have the following confusion matrix: enter image description here

I would like to change the format of the numbers that, when they exceed the value 99, appear in scientific format. I would like them to appear in a standard format. That is: 3.3e + 02 would be 330.

This is the function I have implemented:

  cm= confusion_matrix(y_test,predicted_classes)
  plt.figure(figsize=fig_size)
  plt.title('Confusion matrix of the classifier')
  sns.heatmap(cm,annot=True)
  plt.xlabel('Predicted')
  plt.xticks(rotation=45)
  plt.ylabel('True')
  plt.ioff()
  plt.show()
Était-ce utile?

La solution

Add fmt = ".1f" parameter in sns.heatmap().

You can rewrite your code as follows to get all numbers in scientific format.

sns.heatmap(cm,annot=True, fmt=".1f")

Refer this link for additional customization.

Licencié sous: CC-BY-SA avec attribution
scroll top