如何可视化混淆矩阵

import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import confusion_matrix
def plot_confusion_matrix(confusion_mat):
    plt.imshow(confusion_mat)
    plt.title('Confusion Matrix')
    plt.colorbar()
    
    labels = ['a', 'b', 'c', 'd']
    tick_marks = np.arange(len(labels))
    plt.xticks(tick_marks, labels)
    plt.yticks(tick_marks, labels)
    plt.ylabel('True Label')
    plt.xlabel('Predicted Label')
    plt.show()
if __name__ == '__main__':
    y_true = [1, 0, 0, 2, 1, 0, 3, 3, 3]
    y_pred = [1, 1, 0, 2, 1, 0, 1, 3, 3]
    confusion_mat = confusion_matrix(y_true, y_pred)
    plot_confusion_matrix(confusion_mat)
    

 

对角线越亮越好

其中y_true: array,  shape=[n_sample]

       y_pred: array, shape=[n_sample]

      confusion_matrix的返回值: array, shaple=[n_classes, n_classes]

混淆矩阵是总结分类模型预测结果的清醒分析表,属于机器学习的范畴,具体以矩阵形式将数据集中的记录按照真实的类别与分类模型作出的分类判断两个标准进行汇总。名字来源于他可以容易的表明多个类别是否有混淆(也就是一个class被预测成另一个class)

结果显示的意义:

 ABCD
A实际A  - 预测A实际A - 预测B实际A - 预测C实际A - 预测D
B实际B - 预测A实际B - 预测B实际B - 预测C实际B - 预测D
C实际C - 预测A实际C - 预测B实际C - 预测C实际C - 预测D
D实际D - 预测A实际D - 预测B

实际D - 预测C

实际D - 预测D

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值