简体   繁体   English

R,混淆矩阵百分比

[英]R, Confusion Matrix in percent

In R how to get Confusion Matrix in percent (or fraction of 1). 在R中如何以百分比(或1的分数)获得混淆矩阵。 The "caret" package provides useful function but shows absolute number of samples. “插入符号”包提供了有用的功能,但显示了绝对的样本数。

library(caret)
data(iris)
T <- iris$Species
P <- sample(iris$Species)
confusionMatrix(P, T)
Confusion Matrix and Statistics
             Reference
Prediction   setosa versicolor virginica
setosa         15         16        19
versicolor     19         16        15
virginica      16         18        16

The caret function is nice if you want all the summary statistics. 如果您想要所有摘要统计信息,则插入符函数很好。 If all you care about is the 'percentage' confusion matrix, you can just use prop.table and table . 如果你关心的只是'百分比'混淆矩阵,你可以使用prop.tabletable Also, for future reference, strictly programming questions should be posted to stackoverflow not CrossValidated. 此外,为了将来参考,严格的编程问题应该发布到stackoverflow而不是CrossValidated。

prop.table(table(P,T))
> prop.table(table(P,T))
            T
P                setosa versicolor  virginica
  setosa     0.11333333 0.10666667 0.11333333
  versicolor 0.09333333 0.13333333 0.10666667
  virginica  0.12666667 0.09333333 0.11333333

If you would like to keep the summary statistics from caret, just you prop.table on the confusion matrix object. 如果您想保留来自插入符号的摘要统计信息,只需在混淆矩阵对象上进行预测。

prop.table(caret::confusionMatrix(P,T)$table)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM