Skip to content

Instantly share code, notes, and snippets.

@vikramsoni2
Created March 25, 2021 03:05
Show Gist options
  • Save vikramsoni2/3293b5dab320ba6d67eb8eed415e1c04 to your computer and use it in GitHub Desktop.
Save vikramsoni2/3293b5dab320ba6d67eb8eed415e1c04 to your computer and use it in GitHub Desktop.
Multiclass confusion matrix using Seaborn heatmap
y_true = le.inverse_transform(y_valid)
y_pred = le.inverse_transform(y_valid_pred_lr)
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
data = confusion_matrix(y_true, y_pred)
df_cm = pd.DataFrame(data, columns=np.unique(y_true), index = np.unique(y_true))
df_cm.index.name = 'Actual'
df_cm.columns.name = 'Predicted'
f, ax = plt.subplots(figsize=(15, 15))
cmap = sns.cubehelix_palette(light=1, as_cmap=True)
sns.heatmap(df_cm, cbar=False, annot=True, cmap=cmap, square=True, fmt='.0f',
annot_kws={'size': 10})
plt.title('Actuals vs Predicted')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment