如何在 PRROC 的 ROC 曲线图上添加对角线?

How to add the diagonal line on a ROC curve plot from PRROC?

这里是PRROC中的ROC曲线示例

library(PRROC)
# create artificial scores as random numbers
x <- rnorm( 1000 );
y <- rnorm( 1000, -1 );

# compute area under PR curve
pr <- pr.curve( x, y );
print( pr );

# compute area under ROC curve
roc <- roc.curve( x, y );
print( roc );

# compute PR curve and area under curve
pr <- pr.curve( x, y, curve = TRUE );
# plot curve
plot(pr);

# compute ROC curve and area under curve
roc <- roc.curve( x, y, curve = TRUE );
# plot curve
plot(roc);

我想在这个带有彩色线条的原始图中添加一条对角线,但坐标总是错误的。

下面的代码可以工作。如果您安装了 ggplot2 包。

如果你没有安装 ggplot2。 运行这段代码先

install.packages("ggplot2")

然后 运行 下面的代码

library(PRROC)
# create artificial scores as random numbers
x <- rnorm( 1000 );
y <- rnorm( 1000, -1 );

data = as.data.frame(cbind(x,y))
# compute area under PR curve
pr <- pr.curve( x, y );
print( pr );

# compute area under ROC curve
roc <- roc.curve( x, y );
print( roc );

# compute PR curve and area under curve
pr <- pr.curve( x, y, curve = TRUE );
# plot curve
plot(pr);

# compute ROC curve and area under curve
roc <- roc.curve( x, y, curve = TRUE );
# plot curve
plot(roc)

library(ggplot2)
data <- as.data.frame(roc$curve)
data <- data[,1:2]
ggplot(data, aes(x=data$V1, y=data$V2))+geom_line()+ geom_abline(slope = 1)

我没有那个包,也没用过。也就是说,我看到 CRAN 网站上列出了一个小插图。查看小插图,似乎有 min.plotrand.plot 参数。由于 ROC 图上的对角线表示最小值/完全随机模型在长 运行 中的表现,其中之一可能会创建您想要的线。