计算R中混淆矩阵的准确度和精度

Aja*_*ngh 10 r sentiment-analysis confusion-matrix

是否有任何工具/ R包可用于计算R中混淆矩阵的准确度和精度?

公式和数据结构在这里

Nis*_*yal 27

是的,您可以使用混淆矩阵计算R中的精度和精度.它使用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))

xtab <- table(pred, truth)
# load Caret package for computing Confusion matrix
library(caret) 
confusionMatrix(xtab)
Run Code Online (Sandbox Code Playgroud)

xtab的混淆矩阵将是这样的:

Confusion Matrix and Statistics

          truth
pred       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

       'Positive' Class : abnormal
Run Code Online (Sandbox Code Playgroud)

所以这就是你想要的一切.

  • 如何在混淆矩阵(xtab)得到结果后以编程方式找到精度和召回? (3认同)

BGA*_*BGA 12

@Harsh Trivedi

byClass允许您从摘要中提取精度召回.PPV很精确.敏感性是召回.https://en.wikipedia.org/wiki/Precision_and_recall

library(caret)

result <- confusionMatrix(prediction, truth)
precision <- result$byClass['Pos Pred Value']    
recall <- result$byClass['Sensitivity']
Run Code Online (Sandbox Code Playgroud)

我想你想要提出精确度并召回以计算f值,所以就这样了.

f_measure <- 2 * ((precision * recall) / (precision + recall))
Run Code Online (Sandbox Code Playgroud)

我还找到了这个方便的在线计算器进行健全检查. http://www.marcovanetti.com/pages/cfmatrix/?noc=2

-bg