【问题标题】:R pROC precisionR pROC 精度
【发布时间】:2018-07-17 03:33:46
【问题描述】:

我想使用 pROC 包并找到精度。问题是我没有 TP/TN/FP/FN 值。相反,我有“好”或“差”分类的给定概率,就像这样:

    GoodPoor=c("Good","Good","Poor","Poor","Good","Good","Poor","Poor","Good","Poor")
    prob1=c(0.73, 0.69, 0.44, 0.55, 0.67, 0.47, 0.08, 0.15, 0.45, 0.35)

所以我创建了 roc() 对象,并给出了我想要的阈值

    M1=as.list(cbind(GoodPoor, prob1))
    roc1_t5<-roc(GoodPoor ~ prob1, M1, thresholds = 0.5)

现在,我知道 pROC 包通过 roc1_t5$sensitivities 和 roc1_t5$specificities 提供了特异性和敏感性,但它似乎没有提供精确度。我的问题是:有没有办法在不使用其他“roc”包的情况下获得精度?感谢您的宝贵时间

【问题讨论】:

  • 精确度是指精确度。精度=TP/(TP+FP)

标签: r precision proc


【解决方案1】:

只要您还提供阈值,coords 函数将返回 ROC 曲线的精度(以及其他值,如果需要的话)。

例子:

> coords(roc1_t5, 0.5, ret=c("threshold", "precision", "recall"))
threshold precision    recall 
0.5000000 0.6666667 0.8000000 

示例以及sapply 的使用,因此您可以在更改阈值时看到值:

> sapply(seq(0, 1, by=0.05), function(x) coords(roc1_t5, x, ret=c("precision", "recall")))
          [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]     [,11]     [,12]
precision  NaN  NaN  1.0  1.0  1.0  1.0  1.0  1.0  1.0   0.8 0.6666667 0.7142857
recall       0    0  0.2  0.4  0.4  0.4  0.4  0.6  0.6   0.8 0.8000000 1.0000000
              [,13]     [,14]     [,15] [,16] [,17] [,18] [,19] [,20] [,21]
precision 0.7142857 0.7142857 0.5555556   0.5   0.5   0.5   0.5   0.5   0.5
recall    1.0000000 1.0000000 1.0000000   1.0   1.0   1.0   1.0   1.0   1.0

还要检查特定阈值的"all" 值位置:

> coords(roc1_t5, "all", ret = c("threshold", "recall", "precision"))
      all       all   all       all       all  all   all   all  all   all  

all
threshold Inf 0.7100000 0.680 0.6100000 0.5100000 0.46 0.445 0.395 0.25 0.115 -Inf
recall    1.0 1.0000000 1.000 1.0000000 0.8000000 0.80 0.800 0.600 0.40 0.200    0
precision 0.5 0.5555556 0.625 0.7142857 0.6666667 0.80 1.000 1.000 1.00 1.000  NaN

最后,您的另一个选择是将精度和召回率一起绘制:

plot(precision ~ recall, t(coords(roc1_t5, "all", ret = c("recall", "precision"))), type="l")

查看文档中ret 参数的更多可能性:

?coords

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多