# https://www.cnblogs.com/yexionglin/p/11432180.html import seaborn as sns from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt from colorama import Fore,Back,Style def draw(y_true, y_pred): min_len = min( len(y_true), len(y_pred) ) sns.set() f, ax=plt.subplots() # y_true = [0,0,1,2,1,2,0,2,2,0,1,1] # y_pred = [1,0,1,2,1,0,0,2,2,0,1,1] cm = confusion_matrix(y_true, y_pred, labels=[-1] * min_len) print(cm) #打印出来看看 sns.heatmap(cm, annot=True, ax=ax) #画热力图 def draw2(y_true, y_pred): min_len = min( len(y_true), len(y_pred) ) print('\t', end='') for i in range(min_len): y_true_format = str(y_true[i])[:3] print('%s\t' % y_true_format, end='') print('') for i in range(min_len): print(Fore.RESET + '%s\t' % str(i + 1), end='') for j in range(i): print('\t', end='') # print with color if y_pred[i] > 0.5: print(Fore.GREEN + str(y_pred[i])) else: print(Fore.RED + str(y_pred[i])) if __name__ == '__main__': draw2( [1.0] * 13, [0.5] * 13 )