插入符号 - 调整参数网格应该有列mtry

cs0*_*815 8 r r-caret

我正在使用此代码:

    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
        )
Run Code Online (Sandbox Code Playgroud)

但得到:

The tuning parameter grid should have columns mtry
Run Code Online (Sandbox Code Playgroud)

我安装了最新的软件包,因为有些人建议这样做,并尝试使用.mtry.有任何想法吗?(是的,我用谷歌搜索,看看SO)

cs0*_*815 2

我已经把它带回到基础知识(虹膜)。这有效 - 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
Run Code Online (Sandbox Code Playgroud)

抱歉浪费您的时间!