使用ggplot2包绘制ROC曲线
rocplot<- function(pred, truth, ...){
predob<- prediction(pred, truth)
#打印AUc
perf.auc<- performance(predob, measure = 'auc', x.measure = 'cutoff')
#
perf<- performance(predob, 'tpr','fpr')
df<- data.frame(x = attributes(perf)$x.values[[1]],y = attributes(perf)$y.values[[1]])
p <- ggplot(data = df)
p + geom_line(aes(x,y),colour = "yellowgreen",size = 1) +
geom_ribbon(aes(x,ymin = 0,ymax = y),fill = alpha("yellowgreen",0.5)) +
labs(title = paste("ROC Curve & AUC:",([email protected]))) +
xlab("Specificity") +
ylab("Sensitivity") +
theme(plot.title = element_text(size = 17))
}
rocplot((model1.prob), data2[test, ]$results)