con_mat = confusion_matrix(Y_test, Y_pred) # 归一化 # con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # con_mat_norm = np.around(con_mat_norm, decimals=2) classes = ['N', 'A', 'V', 'L', 'R'] # 绘图 plt.figure(figsize=(8, 8)) seaborn.heatmap(con_mat, annot=True, fmt='.20g', cmap='BrBG_r') # 绘制热力图 plt.title('confusion_matrix') plt.ylim(0, 5) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show() 12345678910111213
from sklearn.metrics import confusion_matrix from sklearn.metrics import recall_score import matplotlib.pyplot as plt # 预测数据,predict之后的预测结果集 guess = [1, 0, 1, 2, 1, 0, 1, 0, 1, 0] # 真实结果集 fact = [0, 1, 0, 1, 2, 1, 0, 1, 0, 1] # 类别 classes = list(set(fact)) # 排序,准确对上分类结果 classes.sort() # 对比,得到混淆矩阵 confusion = confusion_matrix(guess, fact) # 热度图,后面是指定的颜色块,gray也可以,gray_x反色也可以 plt.imshow(confusion, cmap = plt.cm.Blues) # 这个东西就要注意了 # ticks 这个是坐标轴上的坐标点 # label 这个是坐标轴的注释说明 indices = range(len(confusion)) # 坐标位置放入 # 第一个是迭代对象,表示坐标的顺序 # 第二个是坐标显示的数值的数组,第一个表示的其实就是坐标显示数字数组的index,但是记住必须是迭代对象 plt.xticks(indices, classes) plt.yticks(indices, classes) # 热度显示仪?就是旁边的那个验孕棒啦 plt.colorbar() # 就是坐标轴含义说明了 plt.xlabel('guess') plt.ylabel('fact') # 显示数据,直观些 for first_index in range(len(confusion)): for second_index in range(len(confusion[first_index])): plt.text(first_index, second_index, confusion[first_index][second_index],va = 'center',ha = 'center') # 显示 plt.show()
12345678910111213141516171819202122232425262728293031323334353637383940# confusion_matrix import numpy as np import matplotlib.pyplot as plt classes = ['A', 'B', 'C', 'D', 'E'] confusion_matrix = np.array([(9, 1, 3, 4, 0), (2, 13, 1, 3, 4), (1, 4, 10, 0, 13), (3, 1, 1, 17, 0), (0, 0, 0, 1, 14)], dtype = np.float64) plt.imshow(confusion_matrix, interpolation = 'nearest', cmap = plt.cm.Oranges) # 按照像素显示出矩阵 plt.title('confusion_matrix') plt.colorbar() tick_marks = np.arange(len(classes)) plt.xticks(tick_marks, classes) plt.yticks(tick_marks, classes) # iters = [[i,j] for i in range(len(classes)) for j in range((classes))] # ij配对,遍历矩阵迭代器 iters = np.reshape([[[i, j] for j in range(5)] for i in range(5)], (confusion_matrix.size, 2)) for i, j in iters: plt.text(j, i, format(confusion_matrix[i, j])) # 显示对应的数字 plt.ylabel('Real label') plt.xlabel('Prediction') plt.tight_layout() plt.show()
123456789101112131415161718192021222324252627相关知识
confusion
【数学】矩阵白化原理及推导
抖音KOC矩阵推广类型有哪些 抖音KOC矩阵推广类型分析
深入解析Yolov7模型训练结果及评估
机器学习模型评估的重要指标:精确率、召回率、F1Score
设A为三阶矩阵,P=(α 1 ,α 2 ,α 3 )为可逆矩阵,使得P
设A是实对称矩阵,C是实可逆矩阵,B=CTAC.则( )
6种常见疾病易与灰指甲混淆
评价深度学习模型训练效果的曲线图
SPACE LOOP空间巡环——乐扑矩阵
网址: 混淆矩阵 https://m.mcbbbk.com/newsview472779.html
上一篇: 学配色!详解对比色调搭配技巧② |
下一篇: DNF: 2017-2019春节 |