如何生成正预测值(PPV)相对于分类的各个临界点的图? [英] How can I generate a plot of positive predictive value (PPV) vs various cut-off points for classifications?

查看:66
本文介绍了如何生成正预测值(PPV)相对于分类的各个临界点的图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经生成了一些分数以帮助预测某事物是是(1)还是不是(0),假设数据由以下内容组成:

I have generated some scores to help predict whether or not something is yes (1) or no (0), let's say the data consists of:

scores = c(10:20)

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

mydata = data.frame(scores, response)

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

I can do an ROC analysis, which gives an AUC of .77:

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

现在,究竟如何我看到当选择不同的截断会发生什么?我想在x轴(例如13,14,15,16,17)上设置截止点,在y轴上设置PPV.有什么好办法做到这一点?我需要什么功能/软件包?

Now, how exactly do I see what happens when various cut-offs are chosen? I'd like to have cut-offs on the x-axis (let's say 13,14,15,16,17) and PPV on the y-axis. What's a nice way of doing this? What functions/packages do I need?

推荐答案

我将基于pROC软件包*给出答案.使用ROCR软件包也可以获得类似的结果.

I will give an answer based around the pROC package*. It is possible to obtain similar results using the ROCR package as well.

您要使用 coords 函数,该函数可以在某些给定的阈值下计算多个常用统计信息.例如,为了获得所有阈值的PPV,您可以执行以下操作:

You want to use the coords function, which can compute several common statistics at some given thresholds. For instance, in order to get the PPV at all thresholds, you can do the following:

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

然后您可以绘制这些值:

You can then plot those values:

plot(t(coordinates))

用感兴趣的阈值替换全部" :

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

*免责声明:我是pROC软件包的作者.

这篇关于如何生成正预测值(PPV)相对于分类的各个临界点的图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆