[英]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);
我想在这个原始的 plot 中添加一条彩色线的对角线,但坐标总是错误的。
下面的代码将起作用。 前提是您安装了 ggplot2 package。
如果您没有安装 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)
我没有那个package,也没用过。 也就是说,我看到 CRAN 网站上列出了一个小插图。 查看小插图,似乎有min.plot
和rand.plot
arguments。 由于 ROC plot 上的对角线代表最小值/从长远来看完全随机的 model 应该如何执行,其中之一可能会创建您所追求的线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.