names(res$trainingData) %in% as.character(form[[2]]) 中的错误:缺少参数“form”,无默认值

Error in names(res$trainingData) %in% as.character(form[[2]]) : argument "form" is missing, with no default

提问人:Julien 提问时间:9/7/2023 最后编辑:desertnautJulien 更新时间:9/7/2023 访问量:44

问:

尝试调整 XGBoost 模型的超参数时:

library(caret)

ctrl <- trainControl(
  method = "cv",      
  number = 2,
  verboseIter = TRUE,   
  search = "grid"     
)

param_grid <- expand.grid(
  nrounds = c(1000),          
  eta = c(0.01, 0.1, 0.3),              
  max_depth = c(3),              
  min_child_weight = c(1),     
  subsample = c(0.9),       
  colsample_bytree = c(0.9), 
  gamma = c(0)
)

xgb_tune <- train(
  formula = as.formula(paste("mpg", "~ .")),
  data = mtcars, 
  method = "xgbTree",
  trControl = ctrl,
  tuneGrid = param_grid
)

我收到以下警告和错误:

WARNING: src/learner.cc:767: 
Parameters: { "formula" } are not used.
Error in names(res$trainingData) %in% as.character(form[[2]]) : 
  argument "form" is missing, with no default
机器学习 XGBoost R-Caret 超参数

评论


答:

1赞 desertnaut 9/7/2023 #1

正如警告的那样,该函数不包含参数,您实际上并不需要它;将其更改为简单trainformula

xgb_tune <- train(
  mpg~.,           # change here
  data = mtcars, 
  method = "xgbTree",
  trControl = ctrl,
  tuneGrid = param_grid
)

你会没事的(刚刚测试过)。