3
votes

I am trying to run "gbm" via caret package in R. Receiving an 'method "gbm.fit" is not found' error. gbm package is loaded, R, RStudio, caret and gbm are updated to their latest versions (see version info below)

Here is an [reproducible] example

loading required packages

library(caret)
library(gbm)
library(foreach)
library(doParallel)
library(magrittr)
library(plyr)

starting parallel (or not starting, the result is the same)

cl=makeCluster(5)
registerDoParallel(cl)

Setting up control parameters for caret - pretty much all default

gbm.fit.control = trainControl(method = "cv", 
                               number = 5,
                               repeats = 1,
                               p = 0.75, 
                               verboseIter = T,
                               returnData = TRUE,
                               summaryFunction = defaultSummary
                               selectionFunction = "best",
                               allowParallel = FALSE)

Setting up grid for parameters search - nothing special

gbmGrid <-  expand.grid(interaction.depth = c(2,5,8),
                        n.trees = c(500,2000,5000),
                        shrinkage = c(0.1,0.01),
                        n.minobsinnode = c(10))

Generating dummy data for the example. Real data is more complex, but the result is the same with this toy example as well

tn.XY=data.frame(y=runif(100), x1=runif(100), x2=runif(100), x3=runif(100))

Attempting to run train function

gbmFit3 <- train(y~x1+x2+x3, data = tn.XY,
                 method = "gbm",
                 trControl = gbm.fit.control,
                 verbose = FALSE,
                 tuneGrid = gbmGrid,
                 ## Specify which metric to optimize
                 metric = "RMSE")

Getting the error = gbm.fit is not found

+ Fold1: shrinkage=0.01, interaction.depth=2, n.minobsinnode=10, n.trees=5000 
model fit failed for Fold1: shrinkage=0.01, interaction.depth=2, n.minobsinnode=10, n.trees=5000 
Error in do.call("gbm.fit", modArgs) : could not find function "gbm.fit"

- Fold1: shrinkage=0.01, interaction.depth=2, n.minobsinnode=10, n.trees=5000 
+ Fold1: shrinkage=0.01, interaction.depth=5, n.minobsinnode=10, n.trees=5000 
model fit failed for Fold1: shrinkage=0.01, interaction.depth=5, n.minobsinnode=10, n.trees=5000 
Error in do.call("gbm.fit", modArgs) : could not find function "gbm.fit"
...
And it continues for every fold

I suspected that it could be an issue with parallel (like in here) for example. However, disabling parallel execution did not help. I am kind of lost. I know some people used caret with a great success. It probably needs something basic, something I am missing.

R Version info

R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
 [1] plyr_1.8.3       magrittr_1.5     doParallel_1.0.8 iterators_1.0.7  foreach_1.4.2    gbm_2.1-06       survival_2.38-3 
 [8] caret_6.0-52     ggplot2_1.0.1    lattice_0.20-33  readr_0.1.1      installr_0.16.0 
1
Now I have to decide how to deal with this - there were some fixes and features in the new version I liked ...Alex Lizz

1 Answers

3
votes

I figured out what was the problem. I thought that instead of deleting my question I will leave it here, maybe it'll help somebody. The problem was that I have installed new version from the github, which by some reason did not have gbm.fit method. So I have reinstalled it from the CRAN repository and the error went away.