zachmayer / caretEnsemble

caret models all the way down :turtle:
Other
226 stars 75 forks source link

Predict function in CaretEnsemble package returns the error: "object nn not found" #246

Open sfallahpour opened 4 years ago

sfallahpour commented 4 years ago

I tried to create an ensemble model using the “CaretEnsemble” package. I wrote the following code

models2 <- caretList( log_sales~., data=train.data.final, trControl=trnCtrl,

tuneList=list( rf=caretModelSpec(method="rf", tuneGrid=expand.grid(.mtry=c(1:8)) ),
nn=caretModelSpec(method="nnet", tuneGrid=expand.grid(.decay = c(0,0.001, 0.01, 0.1, 0.5), .size = c(5:10)), preProcess=c("center", "scale"), linout=TRUE, trace=FALSE, maxit = 1000), gbm=caretModelSpec(method="gbm", tuneGrid=expand.grid(interaction.depth = seq(1, 7, by = 2), n.trees = seq(100, 1000, by = 50), shrinkage = c(0.01, 0.1), n.minobsinnode = 10) ), xgb=caretModelSpec(method="xgbTree", tuneGrid=expand.grid(nrounds = 1000, eta = c(0.01,0.05, 0.07, 0.1), max_depth = c(4:14), gamma=0, colsample_bytree = c(0.75), subsample = c(0.50), min_child_weight =0 ) ) ) )

stack.glm <- caretStack(models2, method="glm", trControl=trnCtrl)

Which runs totally fine but when I try to use the stacked model to predict new data I get the following error:

pred <- predict(stack.glm, newdata = testing) Error in eval(predvars, data, env) : object 'nn' not found

When I run “stack.glm$models$nn” I get the results for neural network but I am not sure if object “nn” in the error message refers to same thing.