Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created June 14, 2024 14:57
Show Gist options
  • Save simonespa/4237d415d17774b745c298f0b429114a to your computer and use it in GitHub Desktop.
Save simonespa/4237d415d17774b745c298f0b429114a to your computer and use it in GitHub Desktop.
Confusion Matrix with Seaborn
from sklearn.metrics import confusion_matrix
import seaborn as sns
import matplotlib.pyplot as plt
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(12,12))
sns.heatmap(data=cm, # Data to plot
square=True, # Make the cells square, looks nicer.
cmap='Reds', # Colour scheme to use
xticklabels=model.classes_, # Labels for axis
yticklabels=model.classes_, # Labels for axis
annot=True, # add numbers to cells
fmt='g'); # format cell numbers as int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment