GBM无法识别调整参数网格

时间:2018-08-16 11:54:43

标签: r r-caret gbm

脚本:

library(caret)
library(gbm)

formula <- price ~ carat + depth + table + x + y + z

mtryGrid <- expand.grid(interaction.depth = seq(1, 7, by = 2),
                    n.trees = seq(100, 1000, by = 50),
                    n.minobsinnode = 10,
                    verbose = FALSE,
                    shrinkage = c(0.01, 0.1))

set.seed(100)
gbm_model <- train(formula, 
               data = diamonds,
               method = "gbm",
               tuneGrid = mtryGrid,
               trControl = trainControl(method = "cv"))

给出错误:

  

错误:调整参数网格应具有n.trees列,   相互作用,深度,收缩,n.minobsinnode

尽管mtryGrid似乎具有所有四个必填列

我正在使用R3.5.1,脱字符号6.0-80,GBM 2.1.3

1 个答案:

答案 0 :(得分:0)

因此,您不应将verbose=FALSE放在expand.grid中。该错误明确表明它只能在expand.grid中使用n.trees,interaction.depth等。删除verbose=FALSE给了我方程式的结果。

我希望这对您有帮助

因此以下内容适用于我的系统。要取消打印,请在训练功能中使用verbose=FALSE

formula <- price ~ carat + depth + table + x + y + z

mtryGrid <- expand.grid(interaction.depth = seq(1, 7, by = 2),
                        n.trees = seq(100, 1000, by = 50),
                        n.minobsinnode = 10,
                        shrinkage = c(0.01, 0.1))


expand.grid(n.trees=c(10,20,60),shrinkage=c(0.05,0.1,0.5),n.minobsinnode = c(3,5),interaction.depth=c(3,5))

set.seed(100)
gbm_model <- train(formula, 
               data = diamonds,
               method = "gbm",
               tuneGrid = mtryGrid,
               trControl = trainControl(method = "cv"), verbose=FALSE)