caretEnsemble错误:FUN(X [[i]],...)中的错误:{....不是TRUE

时间:2018-06-19 11:52:53

标签: r regression r-caret ensemble-learning

我一直试图将来自2个回归模型(glmnet和bagEarth)的预测堆叠在一起,但是我一直在得到“ FUN(X [[i]],...)中的错误:{.... is不正确”消息。根据我的阅读,我已经看到此问题源于重新采样索引,但是由于我正在一起训练模型,因此看不到如何解决该问题。我已经能够使用随机数进行复制:

library(caret)
library(caretEnsemble)
rm(list=ls())

training <- as.data.frame(cbind(runif(24,1,100)
,runif(24,1,100)
,runif(24,1,100)
,runif(24,1,100)
,runif(24,1,100)
,runif(24,1,100)))

colnames(training) <- c("y", "x1", "x2", "x3", "x4", "x5")

set.seed(7)
ctrl <- trainControl(method = "cv", number = 3, returnResamp = "all", classProbs = FALSE, index = createMultiFolds(training$y, k = 3, times = 1))
model_list <- caretList(y~., data = training, trControl = ctrl, metric = "RMSE", methodList = c("glmnet", "bagEarth"))
train_ctrl <- trainControl(method = "cv", number = 3, classProbs = FALSE, savePredictions = TRUE, index = createMultiFolds(training$y, k = 3, times = 1))
glm_ensemble <- caretStack(model_list, method = "glm", metric = "RMSE", trControl = train_ctrl)

我知道我可能在某个地方缺少关键元素,任何输入都值得赞赏。

谢谢, 安东

1 个答案:

答案 0 :(得分:1)

进行一些调试,并且错误来自名为df <- read.table(text = " village A Z Y 1 a 1 1 500 2 a 1 1 400 3 a 1 0 800 4 b 1 0 300 5 b 1 1 700 ", header = T) 的函数。这是一个未导出的函数,它在model_lists中查找控制对象中保存的预测(全部或最终)。您尚未在控制对象中设置的项目。如果添加此选项,一切将正常运行。我确实承认,在这个地方发送错误消息会很好,而不仅仅是抛出错误。

bestPreds