如何从表矩阵计算精度(How to calculate accuracy from table matrix)

编程入门 行业动态 更新时间:2024-10-25 16:24:32
如何从表矩阵计算精度(How to calculate accuracy from table matrix)

我正在使用table来显示kmeans集群的结果与实际的类值。

如何根据该表计算%准确度。 我知道如何手动完成。

Iris-setosa在群集2中全部为50,而Iris-versicolor在另一群集中有两个。

有没有办法计算%像Incorrectly classified instances: 52%

我想按类和集群打印混淆矩阵。 有点像这样:

0 1 <-- assigned to cluster 380 120 | 1 135 133 | 0 Cluster 0 <-- 1 Cluster 1 <-- 0 Incorrectly clustered instances : 255.0 33.2031 %

I'm using table to show results from the kmeans cluster vs. the actual class values.

How can I calculate the % accuracy based on that table. I know how to do it manually.

Iris-setosa had all 50 in cluster 2 while Iris-versicolor had two in the other cluster.

Is there a way to calculate the % like Incorrectly classified instances: 52%

I would like to print the confusion matrix by classes and clusters. Something lke this:

0 1 <-- assigned to cluster 380 120 | 1 135 133 | 0 Cluster 0 <-- 1 Cluster 1 <-- 0 Incorrectly clustered instances : 255.0 33.2031 %

最满意答案

您可以使用diag()在对角线上选择案例,并使用它来计算(in)准确度,如下所示:

sum(diag(d))/sum(d) #overall accuracy 1-sum(diag(d))/sum(d) #incorrect classification

您还可以使用它来计算正确分类的案例数(in):

sum(diag(d)) #N cases correctly classified sum(d)-sum(diag(d)) #N cases incorrectly classified

其中 d是你的混淆矩阵

You can use diag() to select the cases on the diagonal and use that to calculate (in)accuracy as shown below:

sum(diag(d))/sum(d) #overall accuracy 1-sum(diag(d))/sum(d) #incorrect classification

You can also use this to calculate the number of cases (in)correctly classified:

sum(diag(d)) #N cases correctly classified sum(d)-sum(diag(d)) #N cases incorrectly classified

where d is your confusion matrix

更多推荐

本文发布于:2023-07-19 01:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   精度   calculate   matrix   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!