Closed ramars closed 8 years ago
You need to include the eta_range parameter in xgb_cv_bayes function:
xgb_cv_bayes <- function(eta_range, max.depth, min_child_weight, subsample) {
Parameters in function to be optimized must be the same that in bounds, and in the same order.
Thanks @BlindApe. I realize my mistake. Silly one. Thanks again.
Hi Yachen, Thanks for writing this very useful package for R users.
I am facing an issue when I tried to use BayesianOptimization function to tune "eta". I took the same code given in the package documentation (Page 2, example 2, Agaricus dataset) and modified it for tuning "eta". I get the following error -
Error in (function (max.depth, min_child_weight, subsample) : unused argument (eta_range = 0.0275130772264674)
I am not sure if "eta" is allowed for tuning here, but wanted to check. I have pasted the code as well.
Thank you, Ramars
library(xgboost) library(rBayesianOptimization)
data(agaricus.train, package = "xgboost") dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
cv_folds <- KFold(agaricus.train$label, nfolds = 5, stratified = TRUE, seed = 0)
xgb_cv_bayes <- function(max.depth, min_child_weight, subsample) { cv <- xgb.cv(params = list(booster = "gbtree", eta = eta_range, max_depth = max.depth, min_child_weight = min_child_weight, subsample = subsample, colsample_bytree = 0.3, lambda = 1, alpha = 0, objective = "binary:logistic", eval_metric = "auc"), data = dtrain, nround = 100, folds = cv_folds, prediction = TRUE, showsd = TRUE, early.stop.round = 5, maximize = TRUE, verbose = 0) list(Score = cv$dt[, max(test.auc.mean)], Pred = cv$pred) }
OPT_Res <- BayesianOptimization(xgb_cv_bayes, bounds = list(eta_range = c(0.01, 0.03), max.depth = c(2L, 6L), min_child_weight = c(1L, 10L), subsample = c(0.5, 0.8)), init_points = 10, n_iter = 20, acq = "ucb", kappa = 2.576, eps = 0.0, verbose = TRUE)