我正在使用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 classificationYou 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 classifiedwhere d is your confusion matrix
更多推荐
发布评论