如何在插入符号包装中绘制RFE中最佳模型的ROC曲线

时间:2018-10-03 14:24:53

标签: r r-caret roc rfe

在选择RFE插入符号包中的特征之后,是否可以绘制出最佳模型的ROC曲线?

我的代码如下:

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"))

结果:

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  

如何为选择3个变量(AUC = 0.6980)的模型绘制ROC曲线?

1 个答案:

答案 0 :(得分:0)

我想为每个模型看到多个roc曲线,为清楚起见,请以最小化格式作为示例。

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)

enter image description here