使用 R 的 ROC 曲线图错误代码:预测器必须是数字或有序

问题描述

我正在尝试使用 pROC 制作 ROC 曲线,其中包含如下 2 列:(列表继续超过 300 个条目)

Actual_Findings_% Predicted_Finding_Prob
0.23 0.6
0.48 0.3
0.26 0.62
0.23 0.6
0.48 0.3
0.47 0.3
0.23 0.6
0.6868 0.25
0.77 0.15
0.31 0.55

我尝试使用的代码是:

roccurve<- plot(roc(response = data$Actual_Findings_% <0.4,predictor = data$Predicted_Finding_Prob >0.5),legacy.axes = TRUE,print.auc=TRUE,main = "ROC Curve",col = colors)

阳性结果的阈值在哪里 实际_发现_% 0.5 (即为真阳性,actual_finding_% 将小于 0.4,而 Predicted_finding_prob 将大于 0.5)

但是当我尝试绘制此 roc 曲线时,出现错误

"Setting levels: control = FALSE,case = TRUE
Error in h(simpleError(msg,call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'plot': Predictor must be numeric or ordered."

任何帮助将不胜感激!

解决方法

这应该有效:


data <- read.table( text=
"Actual_Findings_%  Predicted_Finding_Prob
0.23    0.6
0.48    0.3
0.26    0.62
0.23    0.6
0.48    0.3
0.47    0.3
0.23    0.6
0.6868  0.25
0.77    0.15
0.31    0.55
",header=TRUE,check.names=FALSE )

library(pROC)

roccurve <- plot(
    roc(
        response = data$"Actual_Findings_%" <0.4,predictor = data$"Predicted_Finding_Prob"
    ),legacy.axes = TRUE,print.auc=TRUE,main = "ROC Curve"
)

现在重要的是 - roc 曲线可以向您展示当您改变分类阈值时会发生什么。所以你做错的一件事是通过设置预测 去执行一件事

然而,这确实提供了完美的分离,我想这很好。 (虽然不利于教育目的。)