6

我有一个包含两列的数据框:score1which isnumerictruth1which is boolean。我想预测truth1使用score1. 为此,我需要一个简单的线性模型,然后要求一个好的阈值,即在我的 ROC 曲线中给我 75%灵敏度的阈值。因此,我这样做:

roc_curve = roc(truth1 ~ score1 , data = my_data)
coords(roc=roc_curve, x = 0.75, input='sensitivity', ret='threshold')

我的问题是坐标返回“NA”,因为 ROC 曲线中没有出现 0.75 的灵敏度。所以这是我的问题:我怎样才能获得灵敏度至少为 0.75 且具有最大特异性的阈值?

4

2 回答 2

12

选项 1:您过滤结果

my.coords <- coords(roc=roc_curve, x = "all", transpose = FALSE)
my.coords[my.coords$sensitivity >= .75, ]

pROC选项 2:您可以通过请求灵敏度介于 75% 和 100% 之间的部分 AUC来欺骗:

roc_curve = roc(truth1 ~ score1 , data = my_data, partial.auc = c(1, .75), partial.auc.focus="sensitivity")

pROC 的所有方法都将遵循此请求,并仅在此感兴趣的领域为您提供结果:

coords(roc=roc_curve, x = "local maximas", ret='threshold', transpose = FALSE)
于 2015-10-15T06:43:03.580 回答
2

为了扩展 Calimo 的出色答案,这里是一个通用的代码片段:

# Specify SENSITIVITY criteria to meet.
Sn.upper <- 1.0
Sn.lower <- 0.5

# Specify SPECIFICITY criteria to meet.
Sp.upper <- 1.0
Sp.lower <- 0.6

# Extract all coordinate values from the ROC curve.
my.coords <- coords(roc=auc, x = "all", transpose = FALSE)

# Identify and print all points on the ROC curve that meet the JOINT sensitivity AND specificity criteria.
my.coords[(my.coords$specificity >= Sp.lower & my.coords$specificity <= Sp.upper & 
            my.coords$sensitivity >= Sn.lower & my.coords$sensitivity <= Sn.upper),]

示例输出:

       threshold specificity sensitivity
all.46    10.950   0.5000000   0.7073171
all.47    11.080   0.5138889   0.7073171
all.48    11.345   0.5138889   0.6829268
all.49    11.635   0.5138889   0.6585366
all.50    11.675   0.5138889   0.6341463
all.51    11.700   0.5277778   0.6341463
all.52    11.725   0.5277778   0.6097561
all.53    11.850   0.5416667   0.6097561
all.54    12.095   0.5555556   0.6097561
于 2018-03-20T02:33:51.807 回答