Confusion matrix is not displayed correctly #124834
Unanswered
MegiMenga
asked this question in
Programming Help
Replies: 1 comment
-
Well code man!!! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Body
Hello,
I've written the following code, but the confusion matrix appears empty (not populated with numbers):
from sklearn.metrics import confusion_matrix
import seaborn as sns
#Get predicted class labels
predicted_labels = np.argmax(predictions, axis=1)
#Convert one-hot encoded labels (y_test) back to integer labels
y_true = np.argmax(y_test, axis=1)
#Compute confusion matrix
cm = confusion_matrix(y_true, predicted_labels)
#Plot the confusion matrix as a heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(cm, annot=True, cmap='Blues', fmt='d')
plt.xlabel('Predicted Labels')
plt.ylabel('True Labels')
plt.title('Confusion Matrix')
plt.xticks(rotation=90)
plt.show()
I'd really appreciate it if anyone got any ideas or tips on how to solve this problem.
Thank you :)
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions