当前位置: 首页 > ops >正文

使用seaborn/matplotlib定制好看的confusion matrix

使用Python seaborn/matplotlib结合pretty-print-confusion-matrix可以制作好看的confusion matrix了。

import numpy as np
import pandas as pd
from pretty_confusion_matrix import pp_matrix #调用pp_matrix#pandas dataframe数据准备
array = np.array([[13,  0,  1,  0,  2,  0],[0, 50,  2,  0, 10,  0],[0, 13, 16,  0,  0,  3],[0,  0,  0, 13,  1,  0],[0, 40,  0,  1, 15,  0],[0,  0,  0,  0,  0, 20]])df_cm = pd.DataFrame(array, index=range(1, 7), columns=range(1, 7))
pp_matrix(df_cm, cmap='PuRd') #matrix plot

import numpy as np
from pretty_confusion_matrix import pp_matrix_from_data#vector数据准备
y_test = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])
predic = np.array([1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 3, 4, 4, 1, 4, 3, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 3, 5, 1, 2, 3, 3, 5, 1, 2,3, 4, 4, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])pp_matrix_from_data(y_test, predic)

pretty-print-confusion-matrix安装

pip install pretty-confusion-matrix

推荐阅读:

Python matplotlib保姆级教程

嫌Matplotlib繁琐?试试Seaborn!

《保姆级R可视化教程》来了!

http://www.xdnf.cn/news/10909.html

相关文章:

  • Spring Boot 的自动装配
  • C++学者给您讲数学之——数列
  • 星野录(博客系统)测试报告
  • 在 Ubuntu 系统上使用 Python 的 Matplotlib 库时遇到的字体缺失问题
  • 武器的攻击判定
  • 多层 PCB 板抄板实操解析:技巧到实操步骤
  • Spring Boot 自动配置原理:从入门到精通
  • MySQL强化关键_019_索引优化
  • ​库存周转战争:用数据驱动取代经验主义,让资金活起来​
  • 7.5- Loading a pretrained LLM
  • 【25.06】FISCOBCOS安装caliper+报错解决
  • Python 元组方法全集详解
  • 登录vmware vcenter报vSphere Client service has stopped working错误
  • H.264编码
  • Axure设计案例:滑动拼图解锁
  • 深度学习介绍
  • web程序设计期末复习-简答题
  • 操作系统 第 39 章 插叙:文件和目录
  • 如何实现RAG与MCP集成
  • 多任务学习(Multi-Task Learning, MTL)
  • unity UI Rect Transform“高”性能写法
  • 52. N 皇后 II【 力扣(LeetCode) 】
  • 网络攻防技术九:网络监听技术
  • Dispatch PDI V2.04 发布预告
  • Ros2 简单构建项目的流程以及涉及的文件作用
  • WAF绕过,网络层面后门分析,Windows/linux/数据库提权实验
  • 【时时三省】(C语言基础)数组作为函数参数
  • 解决Vditor加载Markdown网页很慢的问题(Vite+JS+Vditor)
  • 二分查找和二分答案(基础)
  • C++ Visual Studio 2017厂商给的源码没有.sln文件 易兆微芯片下载工具加开机动画下载。