import seaborn as sns
import matplotlib as mp
import pandas as pd
import numpy as np
from sklearn.metrics import confusion_matrix
%matplotlib inline
mp.rcParams['figure.figsize'] = (22, 18)
labels = [1,2,3,4,5,6,7,8]
# prepare matrix with all zeros
table = pd.DataFrame(np.zeros((len(labels), len(labels))), columns=labels, index=labels)
for sample_label, predicted_label in [(1, 2), (1, 1), (3, 3), (2, 2), (4, 4), (5, 6), (6, 8), (5, 8), (7,7)]:
table.loc[predicted_label][sample_label] += 1
for label in labels:
total = table.loc[label].sum()
for l in labels:
if total > 0:
table.loc[label][l] = table.loc[label][l] / total
matrix = sns.heatmap(table, annot=table, cmap='coolwarm', fmt="0")
matrix.set_title('MINOS: Matriz de Confusão in %')