R 如何将混淆矩阵发送到插入符号';什么是混淆矩阵?

R 如何将混淆矩阵发送到插入符号';什么是混淆矩阵?,r,r-caret,confusion-matrix,R,R Caret,Confusion Matrix,我正在查看此数据集:。我建立了一个ctree: myFormula<-class~. # class is a factor of "+" or "-" ct <- ctree(myFormula, data = train) 你可以看到这并没有加起来:sensitivity=99/(99+20)=99/119=0.831928。在我的confusionMatrix结果中,该值表示特异性。然而,特异性是特异性=D/(B+D)=88/(88+6)=88/94=0.9

我正在查看此数据集:。我建立了一个ctree:

myFormula<-class~.          # class is a factor of "+" or "-"
ct <- ctree(myFormula, data = train)
你可以看到这并没有加起来:
sensitivity=99/(99+20)=99/119=0.831928
。在我的confusionMatrix结果中,该值表示特异性。然而,特异性是
特异性=D/(B+D)=88/(88+6)=88/94=0.9361702
,敏感性值

我尝试过这个
混淆矩阵(td,testPred,positive=“+”)
,但得到了更奇怪的结果。我做错了什么

更新:我还意识到我的混淆矩阵与caret所认为的不同:

   Mine:               Caret:

            td             testPred
   testPred  -  +      td   -  +
          - 99  6        - 99 20
          + 20 88        +  6 88 
如您所见,它认为我的假阳性和假阴性是反向的。

更新:我发现发送数据比将表格作为参数要好得多。从文档中:

参考文献
要用作真实结果的类的系数

我认为这意味着什么符号构成了积极的结果。在我的情况下,这将是一个
+
。然而,“参考”指的是数据集的实际结果,也就是因变量

所以我应该使用
confusionMatrix(testPred,test$class)
。如果您的数据因某种原因出现无序,它会将其转换为正确的顺序(因此正面和负面结果/预测在混淆矩阵中正确对齐)

但是,如果您担心结果是否正确,请安装
plyr
库,并使用
rewave
更改系数:

install.packages("plyr")
library(plyr)
newDF <- df
newDF$class <- revalue(newDF$class,c("+"=1,"-"=0))
# You'd have to rerun your model using newDF
我的困惑矩阵:

        td
testPred  -  +
       - 99  6
       + 20 88
        td
testPred  -  +
       - 99  6
       + 20 88
插入符号混淆矩阵:

        td
testPred  -  +
       - 99  6
       + 20 88
        td
testPred  -  +
       - 99  6
       + 20 88
虽然现在它说的是
$positive:“-”
,所以我不确定这是好是坏

        td
testPred  -  +
       - 99  6
       + 20 88