zachmayer / caretEnsemble

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

caretList trains more models than I'd like #204

Closed pglez82 closed 8 years ago

pglez82 commented 8 years ago

Hello everyone,

I have a very simple question about caretList. I will explain it in a very easy example.

I have trained two models using caretList:

library(caretEnsemble)

x=iris[,1:4]
y=iris[,5]

set.seed(7)

models<-caretList(x,y,methodList=c("rf"),
                     trControl=trainControl(method="cv",number=5,savePredictions="final"),
                     tuneList=list(
                         rf1=caretModelSpec(method="rf", tuneGrid=data.frame(.mtry=c(2,4))),
                         rf2=caretModelSpec(method="rf", tuneGrid=data.frame(.mtry=c(8,10)))
                     ))

I thought that caretList would return 2 models but It returns 3 instead. This extra model has the default caret tuneGrid. Is there any way to avoid creating this third model?

Thank you!

zachmayer commented 8 years ago

The culprit is the methodList=c("rf") argument, which trains models with the default caret tune grid. This should fix the issue:

library(caretEnsemble)
x=iris[,1:4]
y=iris[,5]
set.seed(7)
models<-caretList(x,y,
                     trControl=trainControl(method="cv",number=5,savePredictions="final"),
                     tuneList=list(
                         rf1=caretModelSpec(method="rf", tuneGrid=data.frame(.mtry=c(2,4))),
                         rf2=caretModelSpec(method="rf", tuneGrid=data.frame(.mtry=c(8,10)))
                     ))