【问题标题】:The tuning parameter grid should have columns mtry调整参数网格应该有列 mtry
【发布时间】:2018-06-25 20:05:52
【问题描述】:

我正在尝试通过 Caret 使用 ranger。有趣的是,它会弹出一条错误消息:

Error in train.default(x <- as.matrix(train_data[, !c(excludeVar), with = FALSE]),  : 
  The tuning parameter grid should have columns mtry

所以我检查:

> model_grid
  mtry splitrule min.node.size
1    5      gini            10

我使用的代码:

 mtry <- round(sqrt(ncol(train_data) - 3),0)      # ignore ID fields and target fields

 # parameters
 model_grid <- expand.grid(
   mtry = mtry                                    # mtry specified here
   ,splitrule = "gini"
   ,min.node.size = 10
 )
 model_trcontrol <- trainControl(
   method = "cv",
   number = 2,                                     
   search = "grid",
   verboseIter = FALSE,
   returnData = FALSE,
   savePredictions = "none",          
   classProbs = TRUE,
   summaryFunction = twoClassSummary,
   sampling = "up",                                # over-sampling
   allowParallel = TRUE
 )

 # training
 targetVar = target_fields[i]
 excludeVar = c(ID_fields,targetVar)
 model_train <- train(
   x <- as.matrix(train_data[,!c(excludeVar),with = FALSE]),
   y <- eval(parse(text = paste0("as.factor(train_data$",targetVar,")"))),
   trControl = model_trcontrol,
   tuneGrid = model_grid,
   method = "ranger"
 )

这些代码在我的本地 PC Rstudio 上运行(当我使用少量数据样本时),但在虚拟机 Rstudio 上运行不了。

发生这种情况的任何可能原因?如何解决?

【问题讨论】:

  • 尝试做:model_grid
  • 不幸的是,无法正常工作,但感谢您的建议。
  • 我试过了,它在我的机器上运行,你有没有在每个参数名称前添加.
  • 考虑从 github 安装插入符号:devtools::install_github('topepo/caret/pkg/caret') 和 CRAN 上的最新游侠库。

标签: r r-caret


【解决方案1】:

我遇到了类似的问题。在我使用 devtools 从 GitHub 重新安装插入符号后,它就解决了。

devtools::install_github('topepo/caret/pkg/caret')

【讨论】:

    猜你喜欢
    • 2019-03-20
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 2019-10-15
    • 2020-05-07
    相关资源
    最近更新 更多