我有一个贝叶斯优化代码,它打印带有值和选定参数的结果。我的问题是 - 如何选择最佳组合?我的情况下的 min RMSE 值在不同回合中较低?
代码:
library(xgboost)
library(rBayesianOptimization)
data(agaricus.train, package='xgboost')
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
cv_folds <- KFold(
y
, nfolds = 5
, stratified = TRUE
, seed = 5000)
xgb_cv_bayes <- function(eta, max.depth, min_child_weight, subsample,colsample_bytree ) {
cv <- xgb.cv(params = list(booster = "gbtree"
# , eta = 0.01
, eta = eta
, max_depth = max.depth
, min_child_weight = min_child_weight
, colsample_bytree = colsample_bytree
, subsample = subsample
#, colsample_bytree = 0.3
, lambda = 1
, alpha = 0
, objective = "reg:linear"
, eval_metric = "rmse")
, data = dtrain
, nround = 1000
, folds = cv_folds
, prediction = TRUE
, showsd = TRUE
, early_stopping_rounds = 10
, maximize = TRUE
, verbose = 0
, finalize = TRUE)
list(Score = cv$evaluation_log[,min(test_rmse_mean)]
,Pred = cv$pred
, cb.print.evaluation(period = 1))
}
cat("Calculating Bayesian Optimum Parameters\n")
OPT_Res <- BayesianOptimization(xgb_cv_bayes
, bounds = list(
eta = c(0.001, 0.03)
, max.depth = c(3L, 10L)
, min_child_weight = c(3L, 10L)
, subsample = c(0.8, 1)
, colsample_bytree = c(0.5, 1))
, init_grid_dt = NULL
, init_points = 10
, n_iter = 200
, acq = "ucb"
, kappa = 3
, eps = 1.5
, verbose = TRUE)
最佳答案
从 help(BayesianOptimization)
,参数 FUN
:
您的函数返回 Score = cv$evaluation_log[,min(test_rmse_mean)]
。你想最小化这个值,而不是最大化它。尝试返回负数,以便当返回的值最大化时,您正在最小化 RMSE。 Score = -cv$evaluation_log[,min(test_rmse_mean)]
关于r - r 中的贝叶斯优化 - 结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45239132/