r - 插入符号 R 包中的混淆矩阵
问题描述
我注意到在 caret R 包中混淆矩阵的定义看起来很奇怪。为了说明这一点,我使用包中的示例:
library(caret)
lvs <- c("normal", "abnormal")
truth <- factor(rep(lvs, times = c(86, 258)),
levels = rev(lvs))
pred <- factor(
c(
rep(lvs, times = c(54, 32)),
rep(lvs, times = c(27, 231))),
levels = rev(lvs))
confusionMatrix(pred, truth)
Confusion Matrix and Statistics
Reference
Prediction abnormal normal
abnormal 231 32
normal 27 54
Accuracy : 0.8285
95% CI : (0.7844, 0.8668)
No Information Rate : 0.75
P-Value [Acc > NIR] : 0.0003097
Kappa : 0.5336
Mcnemar's Test P-Value : 0.6025370
Sensitivity : 0.8953
Specificity : 0.6279
Pos Pred Value : 0.8783
Neg Pred Value : 0.6667
Prevalence : 0.7500
Detection Rate : 0.6715
Detection Prevalence : 0.7645
Balanced Accuracy : 0.7616
'Positive' Class : abnormal
从混淆矩阵:敏感性=231/(231+27)= 0.8953488
和特异性= 54/(54+32)=0.627907
,但是,我认为敏感性必须是231/(231+32)=0.878327
和特异性= 54/(54+27)=0.666667
。
有人可以解释吗?