我尝试如下训练随机森林:
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
的错误。但是这个错误是在2016年报告并解决的...我使用的是最新版本的caret
[我使用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
如果您可以在数据集中提供可重现的示例,我将能够更好地检查可能的错误。