错误在“插入”包中“找不到函数”,R。

时间:2022-02-26 22:30:02

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)

我试着在r中通过caret包运行“gbm”,接收一个“方法”gbm。fit“没有发现错误”。gbm包被加载,R, RStudio, caret和gbm被更新到它们的最新版本(参见下面的版本信息)

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

为caret设置控制参数—几乎所有默认设置。

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

得到错误= gbm。没有找到合适的

+ 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.

我怀疑这可能是一个并行的问题(比如在这里)。然而,禁用并行执行并没有帮助。我有点迷路了。我知道有些人非常成功地使用了caret。它可能需要一些基本的东西,一些我不知道的东西。

R Version info

R版本信息

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 个解决方案

#1


1  

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.

我算出了问题所在。我想,我不会删除我的问题,我将把它留在这里,也许它会帮助一些人。问题是我已经从github上安装了新版本,由于某些原因没有gbm。合适的方法。所以我从CRAN存储库重新安装了它,错误就消失了。

#1


1  

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.

我算出了问题所在。我想,我不会删除我的问题,我将把它留在这里,也许它会帮助一些人。问题是我已经从github上安装了新版本,由于某些原因没有gbm。合适的方法。所以我从CRAN存储库重新安装了它,错误就消失了。