How to compute ROC and AUC under ROC after training using caret in R?

后端 未结 2 515
悲哀的现实
悲哀的现实 2020-12-08 05:32

I have used caret package\'s train function with 10-fold cross validation. I also have got class probabilities for predicted classes by setting

2条回答
  •  盖世英雄少女心
    2020-12-08 06:17

    Update 2019. This is what MLeval was written for (https://cran.r-project.org/web/packages/MLeval/index.html), it works with the Caret train output object to make ROCs, PR curves, calibration curves, and calculate metrics, such as ROC-AUC, sensitivity, specificity etc. It just uses one line to do all of this which is helpful for my analyses and may be of interest.

    library(caret)
    library(MLeval)
    
    myTrainingControl <- trainControl(method = "cv", 
                                      number = 10, 
                                      savePredictions = TRUE, 
                                      classProbs = TRUE, 
                                      verboseIter = TRUE)
    
    randomForestFit = train(x = Sonar[,1:60], 
                            y = as.factor(Sonar$Class), 
                            method = "rf", 
                            trControl = myTrainingControl, 
                            preProcess = c("center","scale"), 
                            ntree = 50)
    
    ##
    
    x <- evalm(randomForestFit)
    
    ## get roc curve plotted in ggplot2
    
    x$roc
    
    ## get AUC and other metrics
    
    x$stdres
    

提交回复
热议问题