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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM