Issue
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:
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?
Solution
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')
Answered By - StupidWolf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.