While working with my project, I have obtained a confusion matrix from test data as:
JavaScript
x
4
1
from sklearn.metrics import confusion_matrix
2
cm = confusion_matrix(y_test, y_pred)
3
cm
4
Output as:
JavaScript
1
3
1
array([[1102, 88],
2
[ 85, 725]], dtype=int64)
3
Using seaborn and matplotlib, I visualized it using the code:
JavaScript
1
12
12
1
import seaborn as sns
2
import matplotlib.pyplot as plt
3
4
ax= plt.subplot();
5
sns.heatmap(cm, annot=True,cmap='Blues',ax=ax);
6
# labels, title and ticks
7
ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels');
8
ax.set_ylim(2.0, 0)
9
ax.set_title('Confusion Matrix');
10
ax.xaxis.set_ticklabels(['Fake','Real']);
11
ax.yaxis.set_ticklabels(['Fake','Real']);
12
The output obtained is:
The problem is values with 3 digits (here 1102 been displayed as 11e+03) or above are being displayed in exponential form.
Is there a way to display it in its normal form?
Advertisement
Answer
You can use the "fmt"
option:
JavaScript
1
7
1
cm = np.array([[1102, 88],[85, 725]])
2
3
import seaborn as sns
4
import matplotlib.pyplot as plt
5
6
sns.heatmap(cm, annot=True,fmt="d",cmap='Blues')
7