I am plotting a confussion matrix like this:
from sklearn.linear_model import LogisticRegression
#Initalize the classifier
clf = LogisticRegression(random_state=0)
#Fitting the training data
clf.fit(X_train, y_train)
#Predicting on test
y_pred=clf.predict(X_test)
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))
print(f'Accuracy = {accuracy_score(y_test, y_pred):.2f}\nRecall = {recall_score(y_test, y_pred):.2f}\n')
cm = confusion_matrix(y_test, y_pred)
cm_plot = sns.heatmap(cm, annot=True, cmap='Blues');
cm_plot.set_xlabel('Predicted Values')
cm_plot.set_ylabel('Actual Values')
cm_plot.set_title('Confusion Matrix (with SMOTE)', size=16)
But its showing numbers like 3.3e 02 when the real number confussion matrix values are like this:
[[327 103]
[ 51 346]]
How can I plot the real numbers in the heatmap ?
CodePudding user response:
It seems that you are plotting your heatmap with Seaborn. You can format numbers with seaborn.heatmap
's fmt
argument. Doing cm_plot = sns.heatmap(cm, annot=True, cmap='Blues', fmt='d')
should work.