我想知道是否有某种方法可以将两种不同模型的预测相结合,建立在两种不同的输入特征集上。例如,首先是功能1:10,第二个是11:20,并与caretStack函数的caretEnssemble结合使用。
我在尝试:
data("mtcars")
head(mtcars)
library(caret)
library(caretEnsemble)
library(glmnet)
library(gbm)
ma_control <- trainControl(method = "cv",
number = 2,
summaryFunction = RMSE,
verboseIter = TRUE,
savePredictions = TRUE)
subset1 <- mtcars[,c(2:3,1)]
subset2 <- mtcars[,c(4:5,1)]
classification_formula1 <- as.formula(paste("mpg" ,"~",
paste(names(subset1)[!names(subset1)=='mpg'],collapse="+")))
classification_formula2 <- as.formula(paste("mpg" ,"~",
paste(names(subset2)[!names(subset2)=='mpg'],collapse="+")))
emf_tuneGrid_list <- NULL;
emf_tuneGrid_list$glmnet1_tuneGrid <- expand.grid(alpha = 1.0 ,lambda = 1)
emf_tuneGrid_list$gbm2_tuneGrid <- expand.grid(interaction.depth = 1, n.trees = 101 ,
shrinkage = 0.5 , n.minobsinnode = 5)
emf_model_list <- caretList (
trControl=ma_control, metric = "RMSE",
tuneList=list(
glmnet1= caretModelSpec(method='glmnet', classification_formula = classification_formula1 , data = subset1 , tuneGrid=emf_tuneGrid_list$glmnet1_tuneGrid),
gbm2 = caretModelSpec(method='gbm', classification_formula = classification_formula2, data = subset2 , tuneGrid=emf_tuneGrid_list$gbm2_tuneGrid , verbose = FALSE)
)
)
但是在extractCaretTarget.default(...)中获取错误: 争论&#34; y&#34;缺少,没有默认