R - xgboost超参数调整

时间:2017-07-12 09:20:46

标签: r

尝试优化xgboost并使用以下代码(数据集全部是目标变量的数字,而且是回归(0 - 1值)。

df_train <- train_raw

# set up the cross-validated hyper-parameter search
xgb_grid_1 = expand.grid(
  nrounds = 1000,
  eta = c(0.01, 0.001, 0.0001),
  max_depth = c(2, 4, 6, 8, 10),
  gamma = 1,
  nround = 120,
  max_depth =1

)

# pack the training control parameters
xgb_trcontrol_1 = trainControl(
  method = "cv",
  number = 5,
  verboseIter = TRUE,
  returnData = FALSE,
  returnResamp = "all",                                                        # save losses across all models
  #classProbs = TRUE,                                                           # set to TRUE for AUC to be computed
  summaryFunction = twoClassSummary,
  allowParallel = TRUE
)

x = as.matrix(df_train %>% select(-target))

# train the model for each parameter combination in the grid, 
#   using CV to evaluate
xgb_train_1 = train(
  x = as.matrix(x),
  y = df_train$target,
  trControl = xgb_trcontrol_1,
  tuneGrid = xgb_grid_1,
  method = "xgbTree"
)

我得到的错误是

Error: The tuning parameter grid should have columns nrounds, max_depth, eta, gamma, colsample_bytree, min_child_weight, subsample

我迷失了为什么我的xgb_train_1无法看到xgb_grid_1。有什么想法吗?

0 个答案:

没有答案