ROCR包中ROC曲线计算是取大于cutoff还是大于等于cutoff

找到对应的代码如下

.compute.unnormalized.roc.curve
function (predictions, labels) 
{
    pos.label <- levels(labels)[2]
    neg.label <- levels(labels)[1]
    pred.order <- order(predictions, decreasing = TRUE)
    predictions.sorted <- predictions[pred.order]
    tp <- cumsum(labels[pred.order] == pos.label)
    fp <- cumsum(labels[pred.order] == neg.label)
    dups <- rev(duplicated(rev(predictions.sorted)))
    tp <- c(0, tp[!dups])
    fp <- c(0, fp[!dups])
    cutoffs <- c(Inf, predictions.sorted[!dups])
    return(list(cutoffs = cutoffs, fp = fp, tp = tp))
}

可以看到先按从大到小排序,再累计当前位置和之前位置的阳性值。因此计算TP,TN等指标时,取的是大于等于cutoff

posted @ 2019-07-24 16:33  ywliao  阅读(1390)  评论(0编辑  收藏  举报