gpt4 book ai didi

R插入符的rfe [错误在{: task 1 failed - "rfe is expecting 184 importance values but only has 2"]

转载 作者:行者123 更新时间:2023-12-01 23:45:32 26 4
gpt4 key购买 nike

我将 Caret 的 rfe 用于回归应用程序。我的数据(在 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,Caret 版本 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)

最佳答案

看来您可能有高度相关的预测变量。
在进行特征选择之前,您应该运行:

crrltn = findCorrelation(correlations, cutoff = .90)
if (length(crrltn) != 0)
x <- x[,-crrltn]

如果此后问题仍然存在,则可能与自动生成的折叠内的预测变量的高相关性有关,您可以尝试通过以下方式控制生成的折叠:

set.seed(12213)
index <- createFolds(y, k = 10, returnTrain = T)

然后将这些作为参数传递给 rfeControl 函数:

lmctrl <- rfeControl(functions = lmFuncs, 
method = "repeatedcv",
index = index,
verbose = TRUE)

set.seed(111333)
lrprofile <- rfe( z , x,
sizes = sizes,
rfeControl = lmctrl)

如果您一直遇到同样的问题,请检查每个折叠内的预测变量之间是否存在高度相关:

for(i in 1:length(index)){
crrltn = cor(x[index[[i]],])
findCorrelation(crrltn, cutoff = .90, names = T, verbose = T)
}

关于R插入符的rfe [错误在{: task 1 failed - "rfe is expecting 184 importance values but only has 2"],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29454185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com