Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix the values displayed in a confusion matrix in exponential form to normal form

While working with my project, I have obtained a confusion matrix from test data as:

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm

Output as:

array([[1102,   88],
   [  85,  725]], dtype=int64)

Using seaborn and matplotlib, I visualized it using the code:

import seaborn as sns
import matplotlib.pyplot as plt     

ax= plt.subplot();
sns.heatmap(cm, annot=True,cmap='Blues',ax=ax);
# labels, title and ticks
ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels'); 
ax.set_ylim(2.0, 0)
ax.set_title('Confusion Matrix');
ax.xaxis.set_ticklabels(['Fake','Real']); 
ax.yaxis.set_ticklabels(['Fake','Real']);

The output obtained is:

Confusion matrix

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?

like image 999
Shiva RD Avatar asked Nov 06 '25 01:11

Shiva RD


2 Answers

You can use the "fmt" option:

cm = np.array([[1102,   88],[85,  725]])

import seaborn as sns
import matplotlib.pyplot as plt     

sns.heatmap(cm, annot=True,fmt="d",cmap='Blues')

enter image description here

like image 153
StupidWolf Avatar answered Nov 07 '25 19:11

StupidWolf


By adding fmt="d" parameter worked.

like image 21
Sourav Sharma Avatar answered Nov 07 '25 18:11

Sourav Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!