【问题标题】:R package, Caret RFE function, how to customize metric to use AUC?R包,Caret RFE函数,如何自定义度量来使用AUC?
【发布时间】:2013-08-17 01:15:37
【问题描述】:

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

【问题讨论】:

    标签: r r-caret rfe


    【解决方案1】:

    您必须在您的trainControl() 对象中指定一个自定义summaryFunction(),然后从该summaryFunction() 中选择一个适当的部分指标。 Caret 还包括一个名为twoClassSummary() 的 AUC 函数,因此您甚至没有自己的写入功能。这是一个例子:

    > 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. 
    

    编辑:刚刚意识到你想要它用于rfe() - 同样的事情也成立,但是你必须以同样的方式编辑你的 rfeFuncs 对象的“摘要”元素。例如:

    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
    

    【讨论】:

    • 感谢您提供快速而详细的回答!
    猜你喜欢
    • 2021-04-23
    • 2019-07-28
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2018-03-16
    • 1970-01-01
    相关资源
    最近更新 更多