【问题标题】:Error in { : task 1 failed - "undefined columns selected"{ 中的错误:任务 1 失败 - “选择了未定义的列”
【发布时间】:2020-01-29 22:54:53
【问题描述】:

我尝试如下训练随机森林:

library(caret)
library(randomForest)

nfields <- 5
control <- rfeControl(functions = rfFuncs,
                      method = "repeatedcv",
                      repeats = 1,
                      verbose = TRUE)

fields <- colnames(dtrain)[!colnames(dtrain) %in% "my_target"]
predictors_rfe <- rfe(dtrain[,fields,with=F], dtrain$my_target,
                       rfeControl = control)

随机森林的执行:

+(rfe) fit Fold01.Rep1 size: 120 
-(rfe) fit Fold01.Rep1 size: 120 
+(rfe) imp Fold01.Rep1 
-(rfe) imp Fold01.Rep1 
+(rfe) fit Fold01.Rep1 size:  16 
+(rfe) fit Fold02.Rep1 size: 120 
-(rfe) fit Fold02.Rep1 size: 120 
+(rfe) imp Fold02.Rep1 
-(rfe) imp Fold02.Rep1 
+(rfe) fit Fold02.Rep1 size:  16 
-(rfe) fit Fold02.Rep1 size:  16 
+(rfe) fit Fold02.Rep1 size:   8 
-(rfe) fit Fold02.Rep1 size:   8 
+(rfe) fit Fold02.Rep1 size:   4 
-(rfe) fit Fold02.Rep1 size:   4 
+(rfe) fit Fold03.Rep1 size: 120 
-(rfe) fit Fold03.Rep1 size: 120 
+(rfe) imp Fold03.Rep1 
# ...
+(rfe) fit Fold10.Rep1 size:  16 
-(rfe) fit Fold10.Rep1 size:  16 
+(rfe) fit Fold10.Rep1 size:   8 
-(rfe) fit Fold10.Rep1 size:   8 
+(rfe) fit Fold10.Rep1 size:   4 
-(rfe) fit Fold10.Rep1 size:   4 

然后我得到错误:

{ 中的错误:任务 1 失败 - “选择了未定义的列”

从错误消息中我无法理解出了什么问题……有人可以帮忙吗?

我从here 发现这是caret 的错误。但是这个bug在2016年被报告并解决了……我用的是最新版的caret

【问题讨论】:

    标签: r random-forest r-caret


    【解决方案1】:

    我使用iris 并按照插入符号tutorial 做了一个示例。可能您的错误在于:

    dtrain [, fields, with = F]
    

    请参阅下面使用iris 的示例:

    set.seed(1)
    library(caret)
    
    nfields <- 5
    control <- rfeControl(functions = rfFuncs,
                          method = "repeatedcv",
                          repeats = 1,
                          verbose = F)
    irisx <- iris[,1:4]
    fields <- colnames(irisx)[!colnames(irisx) %in% "Petal.Width"]
    
    predictors_rfe <- rfe(irisx[,fields], 
                          irisx$Petal.Width,
                          rfeControl = control)
    
    predictors_rfe
    
    > predictors_rfe
    
    Recursive feature selection
    
    Outer resampling method: Cross-Validated (10 fold, repeated 1 times) 
    
    Resampling performance over subset size:
    
     Variables  RMSE Rsquared    MAE  RMSESD RsquaredSD   MAESD Selected
             3 0.196   0.9418 0.1519 0.03502     0.0177 0.02608        *
    
    The top 3 variables (out of 3):
       Petal.Length, Sepal.Length, Sepal.Width
    

    如果您可以为您的数据集提供可重现的示例,我将能够更好地检查可能的错误。

    【讨论】:

      猜你喜欢
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多