我将 Caret 的 rfe 用于回归应用程序。我的数据(in data.table
)有 176 个预测变量(包括 49 个因子预测变量)。当我运行该函数时,我收到此错误:
Error in { : task 1 failed - "rfe is expecting 176 importance values but only has 2"
然后,我曾经model.matrix( ~ . - 1, data = as.data.frame(train_model_sell_single_bid))
将因子预测变量转换为虚拟变量。但是,我遇到了类似的错误:
Error in { : task 1 failed - "rfe is expecting 184 importance values but only has 2"
我在 Windows 7(64 位)上使用 R 版本 3.1.1,插入符号版本 6.0-41。我还安装了 Revolution R Enterprise 版本 7.3(64 位)。但同样的错误在 R 版本 3.0.1 和 Caret 版本 6.0-24 的 Amazon EC2 (c3.8xlarge) Linux 实例上重现。
使用的数据集(重现我的错误):
https://www.dropbox.com/s/utuk9bpxl2996dy/train_model_sell_single_bid.RData?dl=0 https://www.dropbox.com/s/s9xcgfit3iqjffp/train_model_bid_outcomes_sell_single.RData?dl=0
我的代码:
library(caret)
library(data.table)
library(bit64)
library(doMC)
load("train_model_sell_single_bid.RData")
load("train_model_bid_outcomes_sell_single.RData")
subsets <- seq(from = 4, to = 184, by= 4)
registerDoMC(cores = 32)
set.seed(1015498)
ctrl <- rfeControl(functions = lmFuncs,
method = "repeatedcv",
repeats = 1,
#saveDetails = TRUE,
verbose = FALSE)
x <- as.data.frame(train_model_sell_single_bid[,!"security_id", with=FALSE])
y <- train_model_bid_outcomes_sell_single[,bid100]
lmProfile_single_bid100 <- rfe(x, y,
sizes = subsets,
preProc = c("center", "scale"),
rfeControl = ctrl)