我正在尝试通过R中的插入符包运行“gbm”。接收'方法“gbm.fit”未找到'错误。 gbm包已加载,R,RStudio,caret和gbm已更新至其最新版本(请参阅下面的版本信息)
这是[可复制的]示例
加载必需的包
library(caret)
library(gbm)
library(foreach)
library(doParallel)
library(magrittr)
library(plyr)
开始并行(或不开始,结果相同)
cl=makeCluster(5)
registerDoParallel(cl)
设置插入符号的控制参数 - 几乎所有默认值
gbm.fit.control = trainControl(method = "cv",
number = 5,
repeats = 1,
p = 0.75,
verboseIter = T,
returnData = TRUE,
summaryFunction = defaultSummary
selectionFunction = "best",
allowParallel = FALSE)
为参数搜索设置网格 - 没什么特别的
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))
为示例生成虚拟数据。真实数据更复杂,但结果与此玩具示例相同
tn.XY=data.frame(y=runif(100), x1=runif(100), x2=runif(100), x3=runif(100))
尝试运行列车功能
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")
找不到错误= gbm.fit
+ 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
我怀疑它可能是并行问题(例如在here中)。但是,禁用并行执行没有帮助。我有点迷茫。我知道有些人使用插头取得了巨大的成功。它可能需要一些基本的东西,我缺少的东西。
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
答案 0 :(得分:2)
我弄清楚问题是什么。我认为不是删除我的问题,而是将它留在这里,也许它会帮助某人。问题是我从github安装了新版本,由于某种原因没有gbm.fit方法。所以我从CRAN存储库重新安装了它,错误就消失了。