当前位置:网站首页>Draw confusion matrix
Draw confusion matrix
2022-06-10 17:40:00 【Guoqingru】
Draw confusion matrix
Obtain confusion matrix
end y_test,y_pred They are one-dimensional test data set label list 、 List of one-dimensional model prediction results
from sklearn.metrics import confusion_matrix # Introduce the corresponding library
cnf_matrix = confusion_matrix(y_test,y_pred)
Get a two-dimensional matrix :
The drawing of confusion matrix ( Detailed instructions ):

class = ['A','B','C','D','E'] # Category label
confusion_matrix = [[9 1 3 4 0 0]
[2,13,1,3,4]
[1 4 10 0 13]
[3 1 1 17 0]
[0 0 0 1 14]]
# Confusion matrix
#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) # The matrix is displayed in pixels
plt.title('confusion_matrix')
plt.colorbar()
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=-45)
plt.yticks(tick_marks, classes)
thresh = confusion_matrix.max() / 2.
#iters = [[i,j] for i in range(len(classes)) for j in range((classes))]
#ij pairing , Traversal matrix iterator
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])) # Display the corresponding number
plt.ylabel('Real label')
plt.xlabel('Prediction')
plt.tight_layout()
plt.show()
The operation effect is as follows :
边栏推荐
- Redis operation set, Zset, hash data types and use of visualization tools
- 2022年茶艺师(中级)操作证考试题库及模拟考试
- 路由器实验之serial接口的静态路由配置(补充)
- [the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
- Designing drugs with code: are we here yet?
- Web3 is the most complete money making secret script. Just read this one
- Gateway服务网关
- Importerror: libgl. so. 1: cannot open shared object file: no such file or directory
- Nacos配置管理
- Accuracy of alphafold and NMR determination of protein structure in solution
猜你喜欢

Make good use of the industrial chain to attract investment, create industrial cluster effect and realize the coordinated development of industries

See how advanced technology changes human life

SVN中的回退操作

2022年G2电站锅炉司炉考试模拟100题及模拟考试

5年后,你将如何融入20万亿美元的「项目经济」

Feign based remote call

Richard Behrman, the founder of dynamic planning

Internet enterprises and chips
![[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language](/img/53/d6f05e8050e27dc9d59f1196753512.png)
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language

Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
随机推荐
Cap version 6.1 Release Notice
Who is using my server? what are you doing? when?
Mapbox GL development tutorial (11): loading line layers
Photoshop如何打开、编辑和导出Webp格式图片的方法
What is the highest compound interest insurance product? How much does it cost a year?
Chongqing's first sci tech Innovation Board IPO is coming
matplotlib plt.text()的具体用法——画图时给图中的点加标签
自定义视图:图形与图像的处理(一):使用简单图片
Simple site backup shell script
How MySQL modifies field type and field length
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
Accuracy of alphafold and NMR determination of protein structure in solution
Example code of PHP for uploading multiple pictures
开源项目 PM 浅谈如何设计官网
为什么宇宙会将最大速度限制在光速
Web3最全搞钱秘籍,看这一篇就够了
web集群基础知识学习(1)
【玩转华为云】鲲鹏DevKit迁移实战
Overseas data centers need to be prepared for unpredictable disasters
Lifeifei: I am more like a scientist in physics than an engineer