R语言绘图:ggplot2绘制ROC

使用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)

转载于:https://www.cnblogs.com/xihehe/p/8298029.html

你可能感兴趣的:(R语言绘图:ggplot2绘制ROC)