5

I wonder if there is some way to combine prediction of two different models are built on two different input feature set . For example , first on features 1:10 and second on 11:20 and combine with caretEnssemble of caretStack function.

I am trying :

 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)
  )
)

But get Error in extractCaretTarget.default(...) : argument "y" is missing, with no default

NiMa
  • 157
  • 1
  • 12
  • A [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would be nice. As it stands now, I cannot run your code – phiver Jan 13 '16 at 07:33
  • I've added reproducible example , trying to pass different classification formula for each model . Seems it isn't possible . Want to be sure – NiMa Jan 13 '16 at 18:12
  • I don't think it's possible. – Zach Jan 20 '17 at 19:55

0 Answers0