【发布时间】:2019-05-11 21:54:28
【问题描述】:
来自 caret::confusionMatrix 的文档:
positive: an optional character string for the factor level that
corresponds to a "positive" result (if that makes sense for your
data). If there are only two factor levels, the first level will
be used as the "positive" result.
这听起来像是可以在多类问题中定义一个正例,从而得到一个经典的二元混淆矩阵,其中正(已定义类)与负(所有其他类)。但是,当在多类数据上使用正属性时,它不会改变混淆矩阵的输出。
# generate fake data
data = data.frame(measured=as.factor(rep(c('A', 'B', 'C'), c(30,40,30))),
modeled=as.factor(rep(c('A', 'B', 'C', 'A'), c(30,10,20,40))))
# get confusion matrix
matrix = caret::confusionMatrix(data$modeled, dat$measured, positive='A')
给了
Confusion Matrix and Statistics
Reference
Prediction A B C
A 30 10 30
B 0 10 0
C 0 20 0
Overall Statistics
Accuracy : 0.4
95% CI : (0.3033, 0.5028)
No Information Rate : 0.4
P-Value [Acc > NIR] : 0.5379
Kappa : 0.1304
Mcnemar's Test P-Value : 5.878e-13
Statistics by Class:
Class: A Class: B Class: C
Sensitivity 1.0000 0.2500 0.0000
Specificity 0.4286 1.0000 0.7143
Pos Pred Value 0.4286 1.0000 0.0000
Neg Pred Value 1.0000 0.6667 0.6250
Prevalence 0.3000 0.4000 0.3000
Detection Rate 0.3000 0.1000 0.0000
Detection Prevalence 0.7000 0.1000 0.2000
Balanced Accuracy 0.7143 0.6250 0.3571
我只是误解了文档还是真的有办法获得二进制矩阵? 我知道,我可以自己产生所需的输出,但如果有机会偷懒,我会接受它。
【问题讨论】:
标签: r classification r-caret