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?
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')

By adding fmt="d" parameter worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With