使用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:",(perf.auc@y.values))) + 
        xlab("Specificity") +
        ylab("Sensitivity") +
        theme(plot.title = element_text(size = 17)) 
}

rocplot((model1.prob), data2[test, ]$results)

相关文章:

  • 2021-10-18
  • 2021-07-18
  • 2021-11-23
  • 2021-08-07
  • 2021-07-02
  • 2021-11-08
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-05-25
  • 2022-12-23
相关资源
相似解决方案