R包,Caret RFE功能,如何定制使用AUC的指标?

use*_*099 4 r rfe r-caret

我想使用AUC作为性能指标,但RFE仅支持RMSE,RSquared,Accuracy,Kappa.如何使用auc等自定义指标?

Dav*_*vid 15

您必须summaryFunction()trainControl()对象中指定自定义,然后从中选择适当的部分度量标准summaryFunction().Caret还包括AUC的功能,twoClassSummary()所以你甚至没有自己的写作.这是一个例子:

> library(caret)
> iris <- iris[1:100,]
> iris$Species <- as.factor(as.character(iris$Species))
> 
> tc <- trainControl(method="cv",summaryFunction=twoClassSummary,classProb=T)
> train.rf <- train(Species ~ .,data=iris, method="rf", trControl=tc, metric =  "ROC")
> train.rf
100 samples
  4 predictors
  2 classes: 'setosa', 'versicolor' 

No pre-processing
Resampling: Cross-Validation (10 fold) 

Summary of sample sizes: 90, 90, 90, 90, 90, 90, ... 

Resampling results across tuning parameters:

  mtry  ROC  Sens  Spec  ROC SD  Sens SD  Spec SD
  2     1    1     1     0       0        0      
  3     1    1     1     0       0        0      
  4     1    1     1     0       0        0      

ROC was used to select the optimal model using  the largest value.
The final value used for the model was mtry = 2. 
Run Code Online (Sandbox Code Playgroud)

编辑:刚刚意识到你想要它rfe()- 同样的事情成立但你必须以相同的方式编辑rfeFuncs对象的"summary"元素.例如:

rfFuncs$summary <- twoClassSummary
rfe(iris[,-5],iris[,5],rfeControl = rfeControl(rfFuncs), s=2:3,metric="ROC")
Recursive feature selection

Outer resampling method: Bootstrap (25 reps) 

Resampling performance over subset size:

 Variables ROC Sens Spec ROCSD SensSD SpecSD Selected
         2   1    1    1     0      0      0        *
         3   1    1    1     0      0      0         
         4   1    1    1     0      0      0         

The top 2 variables (out of 2):
   Petal.Width, Petal.Lengt
Run Code Online (Sandbox Code Playgroud)