只要您还提供阈值,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