找到对应的代码如下

.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

相关文章:

  • 2021-06-17
  • 2022-02-25
  • 2021-12-23
  • 2021-07-07
猜你喜欢
  • 2022-01-13
  • 2022-02-23
  • 2022-12-23
  • 2022-03-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案