【问题标题】:How can I generate a plot of positive predictive value (PPV) vs various cut-off points for classifications?如何生成阳性预测值 (PPV) 与分类的各种截止点的图?
【发布时间】:2017-09-13 12:28:56
【问题描述】:

我已经生成了一些分数来帮助预测某事是 (1) 还是否 (0),假设数据包括:

scores = c(10:20)

response = c(0,0,1,0,1,0,1,1,0,1,1)

mydata = data.frame(scores, response)

我可以进行 ROC 分析,得出的 AUC 为 0.77:

roc(response = mydata$response, predictor = mydata$scores) 

现在,我究竟如何看到选择各种截止时会发生什么?我想在 x 轴(比如说 13、14、15、16、17)和 y 轴上设置 PPV。这样做的好方法是什么?我需要什么功能/包?

【问题讨论】:

  • 几个有用的包是ROCR和verification。

标签: r classification roc


【解决方案1】:

我将根据 pROC 包给出答案*。使用 ROCR 包也可以获得类似的结果。

您想使用coords 函数,它可以在某些给定阈值下计算几个常见的统计数据。例如,为了获得所有阈值的 PPV,您可以执行以下操作:

library(pROC)
r <- roc(response = response, predictor = scores)
coordinates <- coords(r, x = "all", input = "threshold", ret = c("threshold", "ppv"))

然后您可以绘制这些值:

plot(t(coordinates))

用感兴趣的阈值替换"all":

 coordinates <- coords(r, x = c(13, 14, 15, 16, 17), input = "threshold", ret = c("threshold", "ppv"))

* 免责声明:我是 pROC 包的作者。

【讨论】:

  • 能得到作者的回复真是太棒了!将您的工作用于一些重要的事情,非常感谢您!
  • 如果您有一个 PPV 列表,并且希望它返回阈值列表,该怎么办?
  • @PleaseHelp 这是一个不同的问题。在堆栈溢出时,您应该在有后续问题时提出一个新问题。
猜你喜欢
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
相关资源
最近更新 更多