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

问题描述 投票:1回答:2

这里是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);

我想在此原始绘图中添加一条对角线,并使用彩色线条,但是坐标始终是错误的。

r roc
2个回答
0
投票

下面的代码将起作用。如果您已安装ggp​​lot2软件包。

如果您没有安装ggp​​lot2。首先运行此代码

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)

0
投票

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

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.