如何从R中的confusionMatrix中检索总体精度值?

如何从R中的confusionMatrix中检索总体精度值?,r,r-caret,confusion-matrix,R,R Caret,Confusion Matrix,在R插入符号库中,如果我得到下面这样的混淆矩阵,是否有方法检索总体精度0.992?我无法取出这个值,因为我需要存储这个值并将其用于以后的处理。这可能吗 Prediction A B C D E A 1114 2 0 0 0 B 9 745 5 0 0 C 0 6 674 4 0 D 0 0 3

在R插入符号库中,如果我得到下面这样的混淆矩阵,是否有方法检索总体精度0.992?我无法取出这个值,因为我需要存储这个值并将其用于以后的处理。这可能吗

 Prediction    A    B    C    D    E
          A 1114    2    0    0    0
          B    9  745    5    0    0
          C    0    6  674    4    0
          D    0    0    3  640    0
          E    0    0    2    1  718
总体统计

            Accuracy : 0.992         
              95% CI : (0.989, 0.994)
 No Information Rate : 0.286         
 P-Value [Acc > NIR] : <2e-16        

               Kappa : 0.99          

给定一个混淆矩阵
cm
,通过
overall.accurity overall.accurity很好的答案,但是accurity返回一个字符串和一个值,我如何才能访问该值?我是说double@Emixam23您现在可能已经找到了问题的解决方案,但对于正在寻找答案的人,只需在上述括号的前后添加另一个方括号,如下面所示
                     Class: A Class: B Class: C Class: D Class: E
 Sensitivity             0.992    0.989    0.985    0.992    1.000
 Specificity             0.999    0.996    0.997    0.999    0.999
 Pos Pred Value          0.998    0.982    0.985    0.995    0.996
 Neg Pred Value          0.997    0.997    0.997    0.998    1.000
 Prevalence              0.286    0.192    0.174    0.164    0.183
 Detection Rate          0.284    0.190    0.172    0.163    0.183
 Detection Prevalence    0.284    0.193    0.174    0.164    0.184
 Balanced Accuracy       0.996    0.992    0.991    0.996    1.000
###################
## 3 class example

confusionMatrix(iris$Species, sample(iris$Species))

newPrior <- c(.05, .8, .15)
names(newPrior) <- levels(iris$Species)

cm <- confusionMatrix(iris$Species, sample(iris$Species))
> str(cm)
List of 5
 $ positive: NULL
 $ table   : 'table' int [1:3, 1:3] 13 18 19 20 13 17 17 19 14
  ..- attr(*, "dimnames")=List of 2
  .. ..$ Prediction: chr [1:3] "setosa" "versicolor" "virginica"
  .. ..$ Reference : chr [1:3] "setosa" "versicolor" "virginica"
 $ overall : Named num [1:7] 0.267 -0.1 0.198 0.345 0.333 ...
  ..- attr(*, "names")= chr [1:7] "Accuracy" "Kappa" "AccuracyLower" "AccuracyUpper" ...
 $ byClass : num [1:3, 1:8] 0.26 0.26 0.28 0.63 0.63 0.64 0.26 0.26 0.28 0.63 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "Class: setosa" "Class: versicolor" "Class: virginica"
  .. ..$ : chr [1:8] "Sensitivity" "Specificity" "Pos Pred Value" "Neg Pred Value" ...
 $ dots    : list()
 - attr(*, "class")= chr "confusionMatrix"
overall <- cm$overall
> overall
      Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull AccuracyPValue  McnemarPValue 
     0.2666667     -0.1000000      0.1978421      0.3449492      0.3333333      0.9674672      0.9547790 
> overall.accuracy <- overall['Accuracy']