zachmayer / caretEnsemble

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

cannot pass predFixed or mtry in tuneList #220

Open brent-halen opened 7 years ago

brent-halen commented 7 years ago

I'm unable to pass the 'predFixed' or 'mtry' argument to Rborist or ranger respectively when using caretList's tuneList variable.

Minimal, reproducible example:


library(elasticnet)
library(pls)
library(nnet)
library(e1071)
library(randomForest)
library(gbm)
library(plyr)
library(MASS)
library(caretEnsemble)

control <- trainControl(method="repeatedcv", number=10, repeats=3, verboseIter=TRUE)

models <- caretList(
  loss~., data = as.data.frame(Data), verbose=TRUE,
  trControl = control,
  tuneList=list(
    Rborist = caretModelSpec(method = "Rborist",predFixed = 2, nTree = 650),
    gbm1 = caretModelSpec(method="gbm",tuneGrid=expand.grid(.n.trees=650, .interaction.depth=3, .shrinkage = 0.0215, .n.minobsinnode = 10)),
    #gbm1 = caretModelSpec(method="gbm"),
    elm = caretModelSpec(method="elm"),
    mlp = caretModelSpec(method="mlp", size = c(8), maxit = 200),
    kknn = caretModelSpec(method="kknn")
  )
)

The code above is what I was using when I encountered the error. The following dataset will reproduce the same error message.

Minimal dataset:

library(caret)
col <- c(rnorm(10)*2000)
Data <- data.frame(
  X = sample(1:10),
  Y = sample(c("yes", "no"), 10, replace = TRUE)
)
Data <- cbind(Data,col)
colnames(Data)[3] <- "loss"

dmy <- dummyVars(loss~ ., data = Data)
Data.1 <- predict(dmy, newdata=Data)
Data.1.df <- as.data.frame(Data.1)

Data <- Data.1.df
Data <- cbind(Data,col)
colnames(Data)[4] <- "loss"

After I run this code, I get the following error message for each iteration:

""" Error in Rborist.default(x, y, predFixed = param$predFixed, ...) : formal argument "predFixed" matched by multiple actual arguments" """

I will get an equivalent message if I change out Rborist with ranger and predFixed with mtry.

Minimal, runnable code:

library(caret)
col <- c(rnorm(10)*2000)
Data <- data.frame(
  X = sample(1:10),
  Y = sample(c("yes", "no"), 10, replace = TRUE)
)
Data <- cbind(Data,col)
colnames(Data)[3] <- "loss"

dmy <- dummyVars(loss~ ., data = Data)
Data.1 <- predict(dmy, newdata=Data)
Data.1.df <- as.data.frame(Data.1)

Data <- Data.1.df
Data <- cbind(Data,col)
colnames(Data)[4] <- "loss"

library(elasticnet)
library(pls)
library(nnet)
library(e1071)
library(randomForest)
library(gbm)
library(plyr)
library(MASS)
library(caretEnsemble)

control <- trainControl(method="repeatedcv", number=10, repeats=3, verboseIter=TRUE)

models <- caretList(
  loss~., data = as.data.frame(Data), verbose=TRUE,
  trControl = control,
  tuneList=list(
    Rborist = caretModelSpec(method = "Rborist",predFixed = 2, nTree = 650),
    gbm1 = caretModelSpec(method="gbm",tuneGrid=expand.grid(.n.trees=650, .interaction.depth=3, .shrinkage = 0.0215, .n.minobsinnode = 10)),
    #gbm1 = caretModelSpec(method="gbm"),
    elm = caretModelSpec(method="elm"),
    mlp = caretModelSpec(method="mlp", size = c(8), maxit = 200),
    kknn = caretModelSpec(method="kknn")
  )
)

Session Info:

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  splines   stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] caretEnsemble_2.0.0 Rborist_0.1-3       Rcpp_0.12.6        
 [4] MASS_7.3-45         plyr_1.8.4          gbm_2.1.1          
 [7] survival_2.39-4     randomForest_4.6-12 e1071_1.6-7        
[10] nnet_7.3-12         pls_2.5-0           elasticnet_1.1     
[13] lars_1.2            caret_6.0-71        ggplot2_2.1.0      
[16] lattice_0.20-33    

loaded via a namespace (and not attached):
 [1] git2r_0.15.0       compiler_3.3.1     nloptr_1.0.4       iterators_1.0.8   
 [5] class_7.3-14       tools_3.3.1        digest_0.6.10      rpart_4.1-10      
 [9] lme4_1.1-12        memoise_1.0.0      nlme_3.1-128       gtable_0.2.0      
[13] mgcv_1.8-14        Matrix_1.2-7.1     foreach_1.4.3      curl_1.2          
[17] SparseM_1.7        gridExtra_2.2.1    knitr_1.14         httr_1.2.1        
[21] withr_1.0.2        stringr_1.0.0      devtools_1.12.0    MatrixModels_0.4-1
[25] stats4_3.3.1       grid_3.3.1         data.table_1.9.6   R6_2.1.2          
[29] pbapply_1.3-0      tcltk_3.3.1        minqa_1.2.4        reshape2_1.4.1    
[33] car_2.1-3          magrittr_1.5       scales_0.4.0       codetools_0.2-14  
[37] pbkrtest_0.4-6     colorspace_1.2-6   quantreg_5.26      stringi_1.1.1     
[41] munsell_0.4.3      chron_2.3-47  
zachmayer commented 7 years ago

Try putting all the parameters in tuneGrid, instead of passing them directly

Sent from my iPhone

On Oct 26, 2016, at 11:11 PM, brent-halen notifications@github.com wrote:

I'm unable to pass the 'predFixed' or 'mtry' argument to Rborist or ranger respectively when using caretList's tuneList variable.

Minimal, reproducible example:

library(elasticnet) library(pls) library(nnet) library(e1071) library(randomForest) library(gbm) library(plyr) library(MASS) library(caretEnsemble)

control <- trainControl(method="repeatedcv", number=10, repeats=3, verboseIter=TRUE)

models <- caretList( loss~., data = as.data.frame(Data), verbose=TRUE, trControl = control, tuneList=list( Rborist = caretModelSpec(method = "Rborist",predFixed = 2, nTree = 650), gbm1 = caretModelSpec(method="gbm",tuneGrid=expand.grid(.n.trees=650, .interaction.depth=3, .shrinkage = 0.0215, .n.minobsinnode = 10)),

gbm1 = caretModelSpec(method="gbm"),

elm = caretModelSpec(method="elm"),
mlp = caretModelSpec(method="mlp", size = c(8), maxit = 200),
kknn = caretModelSpec(method="kknn")

) ) The code above is what I was using when I encountered the error. The following dataset will reproduce the same error message.

Minimal dataset:

library(caret) col <- c(rnorm(10)*2000) Data <- data.frame( X = sample(1:10), Y = sample(c("yes", "no"), 10, replace = TRUE) ) Data <- cbind(Data,col) colnames(Data)[3] <- "loss"

dmy <- dummyVars(loss~ ., data = Data) Data.1 <- predict(dmy, newdata=Data) Data.1.df <- as.data.frame(Data.1)

Data <- Data.1.df Data <- cbind(Data,col) colnames(Data)[4] <- "loss" After I run this code, I get the following error message for each iteration:

""" Error in Rborist.default(x, y, predFixed = param$predFixed, ...) : formal argument "predFixed" matched by multiple actual arguments" """

I will get an equivalent message if I change out Rborist with ranger and predFixed with mtry.

Minimal, runnable code:

library(caret) col <- c(rnorm(10)*2000) Data <- data.frame( X = sample(1:10), Y = sample(c("yes", "no"), 10, replace = TRUE) ) Data <- cbind(Data,col) colnames(Data)[3] <- "loss"

dmy <- dummyVars(loss~ ., data = Data) Data.1 <- predict(dmy, newdata=Data) Data.1.df <- as.data.frame(Data.1)

Data <- Data.1.df Data <- cbind(Data,col) colnames(Data)[4] <- "loss"

library(elasticnet) library(pls) library(nnet) library(e1071) library(randomForest) library(gbm) library(plyr) library(MASS) library(caretEnsemble)

control <- trainControl(method="repeatedcv", number=10, repeats=3, verboseIter=TRUE)

models <- caretList( loss~., data = as.data.frame(Data), verbose=TRUE, trControl = control, tuneList=list( Rborist = caretModelSpec(method = "Rborist",predFixed = 2, nTree = 650), gbm1 = caretModelSpec(method="gbm",tuneGrid=expand.grid(.n.trees=650, .interaction.depth=3, .shrinkage = 0.0215, .n.minobsinnode = 10)),

gbm1 = caretModelSpec(method="gbm"),

elm = caretModelSpec(method="elm"),
mlp = caretModelSpec(method="mlp", size = c(8), maxit = 200),
kknn = caretModelSpec(method="kknn")

) ) Session Info:

sessionInfo() R version 3.3.1 (2016-06-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.5 LTS

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] parallel splines stats graphics grDevices utils datasets [8] methods base

other attached packages: [1] caretEnsemble_2.0.0 Rborist_0.1-3 Rcpp_0.12.6
[4] MASS_7.3-45 plyr_1.8.4 gbm_2.1.1
[7] survival_2.39-4 randomForest_4.6-12 e1071_1.6-7
[10] nnet_7.3-12 pls_2.5-0 elasticnet_1.1
[13] lars_1.2 caret_6.0-71 ggplot2_2.1.0
[16] lattice_0.20-33

loaded via a namespace (and not attached): [1] git2r_0.15.0 compiler_3.3.1 nloptr_1.0.4 iterators_1.0.8
[5] class_7.3-14 tools_3.3.1 digest_0.6.10 rpart_4.1-10
[9] lme4_1.1-12 memoise_1.0.0 nlme_3.1-128 gtable_0.2.0
[13] mgcv_1.8-14 Matrix_1.2-7.1 foreach_1.4.3 curl_1.2
[17] SparseM_1.7 gridExtra_2.2.1 knitr_1.14 httr_1.2.1
[21] withr_1.0.2 stringr_1.0.0 devtools_1.12.0 MatrixModels_0.4-1 [25] stats4_3.3.1 grid_3.3.1 data.table_1.9.6 R6_2.1.2
[29] pbapply_1.3-0 tcltk_3.3.1 minqa_1.2.4 reshape2_1.4.1
[33] car_2.1-3 magrittr_1.5 scales_0.4.0 codetools_0.2-14
[37] pbkrtest_0.4-6 colorspace_1.2-6 quantreg_5.26 stringi_1.1.1
[41] munsell_0.4.3 chron_2.3-47
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.