简体   繁体   English

是否可以从R中的混淆矩阵中检索假阳性和假阴性?

[英]Is it possible to retrieve false positive and false negative from confusion matrix in R?

I have generated a confusion matrix using R as follows. 我使用R生成了一个混淆矩阵,如下所示。

Is it possible to retrieve the false negative value of 61 from this matrix and assign to a variable in R? 是否可以从该矩阵中检索假负值61并分配给R中的变量? $byClass does't seem to work for this case. $ byClass似乎不适用于这种情况。 Thanks. 谢谢。

Confusion Matrix and Statistics

              Reference
    Prediction   no  yes
           no  9889   61
           yes    6   44

               Accuracy : 0.9933          
                 95% CI : (0.9915, 0.9948)
    No Information Rate : 0.9895          
    P-Value [Acc > NIR] : 4.444e-05       

                  Kappa : 0.5648          
 Mcnemar's Test P-Value : 4.191e-11       

            Sensitivity : 0.9994          
            Specificity : 0.4190          
         Pos Pred Value : 0.9939          
         Neg Pred Value : 0.8800          
             Prevalence : 0.9895          
         Detection Rate : 0.9889          
   Detection Prevalence : 0.9950          
      Balanced Accuracy : 0.7092          

       'Positive' Class : no     

You haven't provided a reproducible example or loaded any packages in your code, but it looks like you're using confusionMatrix from the caret package. 您尚未提供可复制的示例,也未在代码中加载任何包,但似乎您使用的是caret包中的confusionMatrix Here's a generic example: 这是一个通用示例:

library(caret)

# Fake data
dat = data.frame(measured=rep(0:1, c(40,60)), modeled=rep(c(0:1,0:1), c(30,10,20,40)))

# Generate confusion matrix
cm = confusionMatrix(dat$modeled, dat$measured, positive="1")

cm
 Confusion Matrix and Statistics Reference Prediction 0 1 0 30 20 1 10 40 Accuracy : 0.7 95% CI : (0.6002, 0.7876) No Information Rate : 0.6 P-Value [Acc > NIR] : 0.02478 Kappa : 0.4 Mcnemar's Test P-Value : 0.10035 Sensitivity : 0.6667 Specificity : 0.7500 Pos Pred Value : 0.8000 Neg Pred Value : 0.6000 Prevalence : 0.6000 Detection Rate : 0.4000 Detection Prevalence : 0.5000 Balanced Accuracy : 0.7083 'Positive' Class : 1 

cm is actually a list, so let's see what it contains: cm实际上是一个列表,所以让我们看看它包含的内容:

str(cm)

List of 6
 $ positive: chr "1"
 $ table   : 'table' int [1:2, 1:2] 30 10 20 40
  ..- attr(*, "dimnames")=List of 2
  .. ..$ Prediction: chr [1:2] "0" "1"
  .. ..$ Reference : chr [1:2] "0" "1"
 $ overall : Named num [1:7] 0.7 0.4 0.6 0.788 0.6 ...
  ..- attr(*, "names")= chr [1:7] "Accuracy" "Kappa" "AccuracyLower" "AccuracyUpper" ...
 $ byClass : Named num [1:11] 0.667 0.75 0.8 0.6 0.8 ...
  ..- attr(*, "names")= chr [1:11] "Sensitivity" "Specificity" "Pos Pred Value" "Neg Pred Value" ...
 $ mode    : chr "sens_spec"
 $ dots    : list()
 - attr(*, "class")= chr "confusionMatrix"

It looks like cm$table has the actual confusion matrix: 看起来cm$table具有实际的混淆矩阵:

cm$table
  Reference Prediction 0 1 0 30 20 1 10 40 

So the count of false positives is: 因此,误报的计数为:

cm$table[2,1]
 [1] 10 

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

相关问题 从 R 中的矩阵计算真/假阳性和真/假阴性值 - Calculating True/False Positive and True/False Negative Values from Matrix in R R中没有循环的假阳性和假阴性 - False positive and false negative without loop in R 使用R中的正正,负和假正负进行FDR计算? - FDR calculation using True positive, negative and False positive negative in R? R 中有一个函数可以将一个大的混淆矩阵减少到 R 中的 2x2 正负级混淆矩阵吗? - Is there a function in R to reduce a big confusion matrix to a 2x2 positive-negative level confusion matrix in R? 如何从predict()的输出中获得真正的正面否定表? - How to get true positive, false negative table from output of predict()? 假阳性与假阴性权衡 plot - False positive vs. false negative trade off plot R studio - 我需要使用混淆矩阵的灵敏度和特异性以及阳性和阴性预测值的置信区间 - R studio - I need the confidence intervals of sensitivity and specificity and positive and negative predictive values using confusion matrix 在R?中基于TRUE / FALSE矩阵对矩阵进行子集化? - Subseting a matrix based in a TRUE/FALSE matrix in R? 用R中从负到正的数字线填充向量 - filling a vector with a numberline from negative to positive in R 对于R 3.2.2中的对称矩阵,isSymmetric返回FALSE - isSymmetric returns FALSE for symmetric matrix in R 3.2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM