我正在使用此代码:
mtry <- round(sqrt(18), 0)
gbmGrid <- expand.grid(
interaction.depth = c(1, 2, 3, 4, 5, 6)
, n.trees = seq(10, 10000, by = 100)
, shrinkage = 0.01
, n.minobsinnode = c(5, 10, 20, 30)
, distribution = 'gaussian'
, method = 'gbm'
, mtry = mtry
)
fitControl <- trainControl(
method = "repeatedcv"
, number = 2
, repeats = 3
)
gbmFit1 <- train(
Y ~
X1
+ X2
, data = Train
, trControl = fitControl
, tuneGrid = gbmGrid
, verbose = FALSE
)
但得到:
The tuning parameter grid should have columns mtry
我按照某些人的建议安装了最新的软件包,并尝试使用.mtry。有任何想法吗? (是的,我用谷歌搜索,然后看了一下)
最佳答案
我已将其恢复为基本知识(iris)。这行得通-GBM不存在的mtry是问题所在:
library(datasets)
library(gbm)
library(caret)
grid <- expand.grid(
n.trees = seq(10, 1000, by = 100)
, interaction.depth = c(4)
, shrinkage = c(0.01, 0.1)
, n.minobsinnode = c(5, 10, 20, 30)
)
train_control <- trainControl(
method = "repeatedcv"
, number = 10
, repeats = 10
)
model <- train(Petal.Width ~ Petal.Length
, method = 'gbm'
, distribution = 'gaussian'
, data = iris
, trControl = train_control
, tuneGrid = grid
, verbose = FALSE
)
model
抱歉浪费您的时间!
关于r - 插入符-调整参数网格应具有列mtry,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52832898/