'confusion matrix plot is unable to show values within plot
I'm trying to plot confusion matrix, but the plot seems unable to show values at the center.
Code :
plt.figure(figsize=(4,2))
sns.heatmap(cm, annot=True, annot_kws={"size":20},
cmap='Blues', square=True, fmt='.2f')
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.title('Confusion matrix for:\n{}'.format(model.__class__.__name__));
How to have the values 0.45, 0.94, 0.06 and 0.55 to be at the center of square box for better readability ?
Solution 1:[1]
The figure size appears to be too small - 4x2. Also, you are making square=True, the size is not right.
As I dont have the same model, I tried it with another model and this is the code and output
plt.figure(figsize=(4,4))
sns.heatmap((metrics.confusion_matrix(y_test, svmGridtest_predict)),annot=True,
annot_kws={"size":20}, fmt='.2f', square=True, cmap='Blues')
plt.xlabel('Predicted')
plt.ylabel('Actuals',rotation=0)
plt.title('Confusion matrix for:\n{}'.format('SVM'))
OUTPUT figure here...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Redox |


