r - 一张图中有多条 ROC 曲线 ROCR

标签 r plot roc

是否可以使用 ROCR 包在同一图中绘制不同分类器的 roc 曲线?我试过:

>plot(perf.neuralNet, colorize=TRUE)
>lines(perf.randomForest)

但我得到:

Error en as.double(y) : cannot coerce type 'S4' to vector of type 'double'

谢谢!

最佳答案

您的 lines 的问题- 方法是没有通用的S4 performance 类对象的lines 函数ROCR中定义包裹。但是您可以使用通用绘图函数,就像使用附加 add = TRUE 一样。争论。例如,这部分来自 ?plot.performance 的示例页面。 :

library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels )
pred2 <- prediction(abs(ROCR.simple$predictions + 
                        rnorm(length(ROCR.simple$predictions), 0, 0.1)), 
        ROCR.simple$labels)
perf <- performance( pred, "tpr", "fpr" )
perf2 <- performance(pred2, "tpr", "fpr")
plot( perf, colorize = TRUE)
plot(perf2, add = TRUE, colorize = TRUE)

或者,您可以将所有预测存储在一个矩阵中,并一次性执行所有后续步骤:

preds <- cbind(p1 = ROCR.simple$predictions, 
                p2 = abs(ROCR.simple$predictions + 
                rnorm(length(ROCR.simple$predictions), 0, 0.1)))

pred.mat <- prediction(preds, labels = matrix(ROCR.simple$labels, 
                nrow = length(ROCR.simple$labels), ncol = 2) )

perf.mat <- performance(pred.mat, "tpr", "fpr")
plot(perf.mat, colorize = TRUE)

顺便说一句,如果您出于某种原因确实想使用 lines要绘制连续的 ROC 曲线,您必须做某事。像这样:

plot(perf) 
lines(perf2@x.values[[1]], perf2@y.values[[1]], col = 2)

关于r - 一张图中有多条 ROC 曲线 ROCR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085281/

相关文章:

machine-learning - 从最终模型混淆矩阵重新创建 "multiClassSummary"统计数据

r - 如何摆脱 persp() 图的边距?

r - Shiny 的 ggvis react 图

python - Precision-Recall 曲线或 ROC 曲线是否可能是一条水平线?

python - 如何以低延迟和时间来绘制非常大的音频文件以保存文件?

python - 如何创建每个点使用一种颜色的散点图(绘图)

使用 ROCR 包的 R 中的 ROC 曲线

r - 查找 tibble 列中最长的连续条纹

r - 如果数据表列选择器也处于事件状态,如何选择行

r - 错误 BTYD : pnbd. EstimateParameters:L-BFGS-B 需要有限值 'fn'