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

是否可以从R中的混淆矩阵中检索假阳性和假阴性?,r,r-caret,confusion-matrix,R,R Caret,Confusion Matrix,我使用R生成了一个混淆矩阵,如下所示 是否可以从该矩阵中检索61的假负值并分配给R中的变量$byClass似乎对这个案子不起作用。 谢谢 您没有提供可复制的示例,也没有在代码中加载任何包,但看起来您正在使用caret包中的confusionMatrix。以下是一个通用示例: 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)

我使用R生成了一个混淆矩阵,如下所示

是否可以从该矩阵中检索61的假负值并分配给R中的变量$byClass似乎对这个案子不起作用。 谢谢


您没有提供可复制的示例,也没有在代码中加载任何包,但看起来您正在使用
caret
包中的
confusionMatrix
。以下是一个通用示例:

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
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"
看起来
cm$table
有实际的混淆矩阵:

cm$table
因此,误报的计数为:

cm$table[2,1]

您没有提供可复制的示例,也没有在代码中加载任何包,但看起来您正在使用
caret
包中的
confusionMatrix
。以下是一个通用示例:

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
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"
看起来
cm$table
有实际的混淆矩阵:

cm$table
因此,误报的计数为:

cm$table[2,1]

请给出一个可复制的示例:也许
as.matrix()
可以让您获得混淆矩阵中的各个值。请给出一个可复制的示例:也许
as.matrix()
可以让您获得混淆矩阵中的各个值。谢谢。那正是我想要的。谢谢。这正是我要找的。