简体   繁体   中英

How to plot a ROC curve for the best model in RFE in caret package

Is it possible to plot a ROC curve for the best model after feature selection in RFE caret package?

My code is as follow:

set.seed(12)
rfFuncs$summary <- twoClassSummary
rfeControl = rfeControl(rfFuncs)
trainctrl <- trainControl(classProbs= TRUE, summaryFunction = 
twoClassSummary, savePredictions = TRUE)
control <- rfeControl(functions=rfFuncs, method="LOOCV", 
returnResamp="final")
feat.sel <- rfe(bd_ud[, c(1:10)], bd_ud$diagnosis, 
sizes=c(1:10), rfeControl=control, method="svmLinear", metric = 
"ROC",     trControl=trainctrl)
print(feat.sel)
predictors(feat.sel)
plot(feat.sel, type=c("g", "o"))

And the results:

Resampling performance over subset size:

Variables    ROC   Sens   Spec Selected
     1 0.5101 0.6481 0.5185         
     2 0.6337 0.5000 0.5926         
     3 0.6980 0.6296 0.6667        *
     4 0.6373 0.5741 0.6111         
     5 0.6349 0.5741 0.6111         
     6 0.6727 0.6296 0.5926         
     7 0.6406 0.5741 0.5926         
     8 0.6307 0.5926 0.5556         
     9 0.6557 0.5926 0.6111         
    10 0.6044 0.5741 0.5926  

How can I plot the ROC curve for the model that selected 3 variables (AUC=0.6980)?

I would like to see multiple roc curves for each model, see this as example with minimal formatting for clarity purpose.

plot(0:1, 0:1, type = "n")  # setting up coord. system
lines(c(0, 1-0.5926, 1), c(0, 0.5000, 1), lty = 2) # 2 vars ROC
lines(c(0, 1-0.6667, 1), c(0, 0.6296, 1), lty = 1) # 3 vars ROC
legend("top", legend = c("3 vars", "2 vars"), lty = 1:2)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM