简体   繁体   English

在 R 中调整 XGboost 参数

[英]Tuning XGboost parameters In R

I am trying to tune parameters using the caret package in R but get a我正在尝试使用 R 中的 caret 包调整参数,但得到一个

Error in train.default(x = as.matrix(df_train %>% select(-c(Response,  : 
  The tuning parameter grid should have columns nrounds, lambda, alpha 

whenever I try to train the model, even though the columns nrounds, lambda, and alpha are there.每当我尝试训练模型时,即使列 nrounds、lambda 和 alpha 都在那里。

library(caret)
library(xgboost)
library(readr)
library(dplyr)
library(tidyr)

 xgb_grid_1 <- expand.grid(
  nrounds= 2400,
  eta=c(0.01,0.001,0.0001),
  lambda = 1,
  alpha =0
)

xgb_trcontrol <- trainControl(
  method="cv",
  number = 5,
  verboseIter = TRUE,
  returnData=FALSE,
  returnResamp = "all",
  allowParallel = TRUE,

)

xgb_train_1 <- train(
  x = as.matrix(df_train %>% select(-c(Response, Id))),
  y= df_train$Response,
 trControl = xgb_trcontrol,
 tuneGrid = xgb_grid_1,
 method="xgbLinear"
)

The problem lies in your xgb_grid_1.问题在于您的 xgb_grid_1。 If you remove the line eta it will work.如果您删除 eta 行,它将起作用。

Standard tuning options with xgboost and caret are "nrounds", "lambda" and "alpha". xgboost 和 caret 的标准调整选项是“nrounds”、“lambda”和“alpha”。 Not eta.不是埃塔。 use the modelLookup function to see which model parameters are available.使用 modelLookup 函数查看哪些模型参数可用。 If you want to use eta as well, you will have to create your own caret model to use this extra parameter in tuning as well.如果您还想使用 eta,则必须创建自己的插入符号模型以在调整中也使用此额外参数。

modelLookup("xgbLinear")
      model parameter                 label forReg forClass probModel
1 xgbLinear   nrounds # Boosting Iterations   TRUE     TRUE      TRUE
2 xgbLinear    lambda     L2 Regularization   TRUE     TRUE      TRUE
3 xgbLinear     alpha     L2 Regularization   TRUE     TRUE      TRUE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM