批量ROC

作者: 郭师傅 | 来源:发表于2022-09-12 21:33 被阅读0次

    1、建模

    n <- c(8,10,12,17,18,19,20,22,23,24,25)
    # n <- c(8,10,12)
    
    # 向量操作,又快有好
    f_list <- df_all[,n] %>% apply(2,function(x){roc(df_all$fifteen,
                                            
                                            x,
                                            smooth = F,
                                            percent = F,
                                            #plot = T,
                                            print.thres = "best",
    )})
    
    f_before_list <- df_before[,n] %>% apply(2,function(x){roc(df_before$fifteen,
                                                     
                                                     x,
                                                     smooth = F,
                                                     percent = F,
                                                     #plot = T,
                                                     print.thres = "best",
    )})
    
    f_after_list <- df_after[,n] %>% apply(2,function(x){roc(df_after$fifteen,
                                                     
                                                     x,
                                                     smooth = F,
                                                     percent = F,
                                                     #plot = T,
                                                     print.thres = "best",
    )})
    

    2、画图

    fig_1 <- ggroc(f_list,linetype = 1, size = 1,legacy.axes = T) +
    #  ggtitle("ROC curves for comparisions") + 
      #geom_line(aes(x=c(0,1),y=c(1,0)),color = "black",size = 3,linetype=6 )+
      geom_segment(aes(x = 0, y = 0, xend = 1, yend = 1),lty=2, colour = "grey")+
      theme_bw() + 
      theme(legend.position="none") +  # 设置图例位置  
    #  theme(legend.text=element_text(size=10, face="plain"),legend.background = element_blank()) +  # 设置图例字体格式 
      theme(axis.text=element_text(size=10),axis.title=element_text(size=10,face="plain"))
     # guides(col = guide_legend(ncol = 3))
    fig_1
    
    fig_2 <- ggroc(f_before_list,linetype = 1, size = 1,legacy.axes = T) +
    #  ggtitle("ROC curves for comparisions") + 
      #geom_line(aes(x=c(0,1),y=c(1,0)),color = "black",size = 3,linetype=6 )+
      geom_segment(aes(x = 0, y = 0, xend = 1, yend = 1),lty=2, colour = "grey")+
      theme_bw() + 
      theme(legend.position="none") +  # 设置图例位置  
      theme(legend.text=element_text(size=10, face="plain"),legend.background = element_blank()) +  # 设置图例字体格式 
      theme(axis.text=element_text(size=10),axis.title=element_text(size=10,face="plain"))+
      guides(col = guide_legend(ncol = 3))
    fig_2
    
    fig_3 <- ggroc(f_after_list,linetype = 1, size = 1,legacy.axes = T) +
    #  ggtitle("ROC curves for comparisions") + 
      #geom_line(aes(x=c(0,1),y=c(1,0)),color = "black",size = 3,linetype=6 )+
      geom_segment(aes(x = 0, y = 0, xend = 1, yend = 1),lty=2, colour = "grey")+
      theme_bw() + 
      theme(legend.position=c(1.5,0.5)) +  # 设置图例位置  
      theme(legend.text=element_text(size=10, face="plain"),legend.background = element_blank()) +  # 设置图例字体格式 
      theme(axis.text=element_text(size=10),axis.title=element_text(size=10,face="plain"))+
      guides(col = guide_legend(ncol = 1))
    fig_3
    

    3、保存

    fig4 <- plot_grid(fig_1,fig_2,fig_3,ncol = 2,labels = "AUTO")
    ggsave("fig1.pdf",fig4,width =18,height = 17.5,units = "cm")
    

    相关文章

      网友评论

          本文标题:批量ROC

          本文链接:https://www.haomeiwen.com/subject/gvfcortx.html