Change number format of confusion matrix
-
20-10-2020 - |
Question
I have the following confusion matrix:
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()
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange