Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pROC中值灵敏度与手动灵敏度计算-不同结果_R_Roc_Confusion Matrix_Proc R Package - Fatal编程技术网

pROC中值灵敏度与手动灵敏度计算-不同结果

pROC中值灵敏度与手动灵敏度计算-不同结果,r,roc,confusion-matrix,proc-r-package,R,Roc,Confusion Matrix,Proc R Package,从混淆矩阵手动计算灵敏度,得出值0.853。 TN=16 FP=7 FN=5 TP=29 pROC的输出不同(中位数=0.8235) y_test=c(1,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,1,1,1,1,1,1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0) y_pred_prob=c(0.

从混淆矩阵手动计算灵敏度,得出值0.853。

  • TN=16
  • FP=7
  • FN=5
  • TP=29
pROC的输出不同(中位数=0.8235)

y_test=c(1,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,1,1,1,1,1,1,
0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0,
0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0)
y_pred_prob=c(0.63069148,0.65580015,0.9478634,0.94471701,0.24756774,
0.51969906, 0.26881201, 0.6722361 , 0.30275069, 0.61676645,
0.76116789, 0.90867332, 0.31525658, 0.10681422, 0.6890589 ,
0.25185641, 0.54820684, 0.7175465 , 0.57194733, 0.71304872,
0.98805141, 0.92829077, 0.38150015, 0.97653216, 0.96036858,
0.75878699, 0.95466371, 0.52292342, 0.28296724, 0.5660834 ,
0.91581461, 0.49574317, 0.79025422, 0.14303487, 0.66885536,
0.07660444, 0.10342033, 0.53661914, 0.04701796, 0.83313871,
0.37766607, 0.89157993, 0.47731778, 0.62640482, 0.47664294,
0.0928437 , 0.13605622, 0.2561323 , 0.95572329, 0.49051571,
0.49267652, 0.92600581, 0.48464618, 0.96006108, 0.01548211,
0.56057243, 0.82257937)
种子集(99)
boot=2000
rocobj您使用了什么阈值?
在报告和分析混淆矩阵的结果时,您需要小心。在进行数值预测时,必须考虑生成该表的阈值。鉴于其中的数字,我假设您使用的阈值为0.495或接近该阈值的值,这允许我获得与您相同的数字:

> table(y_test, y_pred_prob > 0.495)
      
y_test FALSE TRUE
     0    17    6
     1     5   29
如何从pROC获得经验敏感性和特异性? 现在我们有了一个阈值,可以使用以下函数从pROC中提取该阈值的数据:

> coords(rocobj, 0.495, "threshold", transpose = FALSE)
  threshold specificity sensitivity
1     0.495   0.7391304   0.8529412
这正是您计算的灵敏度

那隆胸呢? 正如您所怀疑的,用于计算置信区间的增强是一个随机过程,重采样曲线的中值将不同于经验值

但是,对于2000次引导复制的中位数,我们非常接近:

> set.seed(99)
> print(ci.thresholds(rocobj,.95, thresholds =  0.495, method = 'bootstrap',boot.n = boot))

95% CI (2000 stratified bootstrap replicates):
 thresholds sp.low sp.median sp.high se.low se.median se.high
      0.495 0.5652    0.7391   0.913 0.7353    0.8529  0.9706

引导是一种基于随机的方法,您应该期望得到不同的结果。例如,尝试更改RNG种子。@RuiBarradas我已经尝试过这样做,但它没有太大变化,如果有的话。所以我很好奇,0.853和0.8235之间的巨大差异是如何产生的……米沙,这是使用0.5的阈值来显示灵敏度的。如果您使用0.5的阈值来获得手动灵敏度(例如
表(预测=y_pred_prob>0.5,实际=y_test)
),则您将获得与所示不同的混淆矩阵。该混淆矩阵的灵敏度为0.8235(它是28/34而不是29/34)。您是否在使用困惑矩阵的最佳截止值?如果是这样,您需要将该值传递给
ci.thresholds
Well done@AllanCameron的threshold参数
> set.seed(99)
> print(ci.thresholds(rocobj,.95, thresholds =  0.495, method = 'bootstrap',boot.n = boot))

95% CI (2000 stratified bootstrap replicates):
 thresholds sp.low sp.median sp.high se.low se.median se.high
      0.495 0.5652    0.7391   0.913 0.7353    0.8529  0.9706