From d0bf5fd842d56f31df4883a23cbb118adbf71df3 Mon Sep 17 00:00:00 2001 From: david-cortes Date: Sat, 14 Dec 2024 20:05:06 +0100 Subject: [PATCH] prefer descriptive parameter names --- R-package/R/callbacks.R | 32 +++++++---- R-package/R/utils.R | 1 - R-package/R/xgb.Booster.R | 10 +--- R-package/R/xgb.create.features.R | 2 +- R-package/R/xgb.cv.R | 2 - R-package/R/xgb.dump.R | 1 - R-package/R/xgb.importance.R | 6 +- R-package/R/xgb.load.R | 1 - R-package/R/xgb.model.dt.tree.R | 1 - R-package/R/xgb.plot.importance.R | 1 - R-package/R/xgb.plot.multi.trees.R | 2 +- R-package/R/xgb.plot.shap.R | 3 +- R-package/R/xgb.plot.tree.R | 1 - R-package/R/xgb.save.R | 1 - R-package/R/xgb.save.raw.R | 1 - R-package/R/xgb.train.R | 8 +-- .../a-compatibility-note-for-saveRDS-save.Rd | 1 - R-package/man/predict.xgb.Booster.Rd | 3 - R-package/man/print.xgb.Booster.Rd | 1 - R-package/man/print.xgb.cv.Rd | 1 - R-package/man/xgb.attr.Rd | 1 - R-package/man/xgb.cb.gblinear.history.Rd | 32 +++++++---- R-package/man/xgb.config.Rd | 1 - R-package/man/xgb.create.features.Rd | 2 +- R-package/man/xgb.cv.Rd | 1 - R-package/man/xgb.dump.Rd | 1 - R-package/man/xgb.importance.Rd | 6 +- R-package/man/xgb.load.Rd | 1 - R-package/man/xgb.model.dt.tree.Rd | 1 - R-package/man/xgb.model.parameters.Rd | 4 +- R-package/man/xgb.plot.importance.Rd | 1 - R-package/man/xgb.plot.multi.trees.Rd | 2 +- R-package/man/xgb.plot.shap.Rd | 3 +- R-package/man/xgb.plot.tree.Rd | 1 - R-package/man/xgb.save.Rd | 1 - R-package/man/xgb.save.raw.Rd | 1 - R-package/man/xgb.train.Rd | 8 +-- R-package/tests/testthat/test_basic.R | 55 ++++++++++++------- .../tests/testthat/test_booster_slicing.R | 2 +- R-package/tests/testthat/test_callbacks.R | 47 +++++++++------- .../tests/testthat/test_custom_objective.R | 2 +- R-package/tests/testthat/test_glm.R | 4 +- R-package/tests/testthat/test_helpers.R | 25 ++++++--- .../testthat/test_interaction_constraints.R | 3 +- R-package/tests/testthat/test_interactions.R | 14 ++++- R-package/tests/testthat/test_monotone.R | 3 +- .../tests/testthat/test_parameter_exposure.R | 4 +- .../tests/testthat/test_poisson_regression.R | 4 +- R-package/tests/testthat/test_ranking.R | 20 +++++-- R-package/tests/testthat/test_unicode.R | 2 +- R-package/tests/testthat/test_update.R | 20 +++++-- R-package/tests/testthat/test_xgboost.R | 4 +- R-package/vignettes/discoverYourData.Rmd | 2 +- R-package/vignettes/xgboostPresentation.Rmd | 18 +++--- 54 files changed, 205 insertions(+), 170 deletions(-) diff --git a/R-package/R/callbacks.R b/R-package/R/callbacks.R index 961715a2e02e..aa8d85246c7e 100644 --- a/R-package/R/callbacks.R +++ b/R-package/R/callbacks.R @@ -960,17 +960,17 @@ xgb.cb.cv.predict <- function(save_models = FALSE, outputmargin = FALSE) { #' booster = "gblinear", #' objective = "reg:logistic", #' eval_metric = "auc", -#' lambda = 0.0003, -#' alpha = 0.0003, +#' reg_lambda = 0.0003, +#' reg_alpha = 0.0003, #' nthread = nthread #' ) #' -#' # For 'shotgun', which is a default linear updater, using high eta values may result in +#' # For 'shotgun', which is a default linear updater, using high learning_rate values may result in #' # unstable behaviour in some datasets. With this simple dataset, however, the high learning #' # rate does not break the convergence, but allows us to illustrate the typical pattern of #' # "stochastic explosion" behaviour of this lock-free algorithm at early boosting iterations. #' bst <- xgb.train( -#' c(param, list(eta = 1.)), +#' c(param, list(learning_rate = 1.)), #' dtrain, #' evals = list(tr = dtrain), #' nrounds = 200, @@ -987,7 +987,7 @@ xgb.cb.cv.predict <- function(save_models = FALSE, outputmargin = FALSE) { #' c( #' param, #' xgb.params( -#' eta = 0.8, +#' learning_rate = 0.8, #' updater = "coord_descent", #' feature_selector = "thrifty", #' top_k = 1 @@ -1000,12 +1000,20 @@ xgb.cb.cv.predict <- function(save_models = FALSE, outputmargin = FALSE) { #' ) #' matplot(xgb.gblinear.history(bst), type = "l") #' # Componentwise boosting is known to have similar effect to Lasso regularization. -#' # Try experimenting with various values of top_k, eta, nrounds, +#' # Try experimenting with various values of top_k, learning_rate, nrounds, #' # as well as different feature_selectors. #' #' # For xgb.cv: #' bst <- xgb.cv( -#' c(param, list(eta = 0.8)), +#' c( +#' param, +#' xgb.params( +#' learning_rate = 0.8, +#' updater = "coord_descent", +#' feature_selector = "thrifty", +#' top_k = 1 +#' ) +#' ), #' dtrain, #' nfold = 5, #' nrounds = 100, @@ -1022,15 +1030,15 @@ xgb.cb.cv.predict <- function(save_models = FALSE, outputmargin = FALSE) { #' booster = "gblinear", #' objective = "multi:softprob", #' num_class = 3, -#' lambda = 0.0003, -#' alpha = 0.0003, +#' reg_lambda = 0.0003, +#' reg_alpha = 0.0003, #' nthread = nthread #' ) #' #' # For the default linear updater 'shotgun' it sometimes is helpful -#' # to use smaller eta to reduce instability +#' # to use smaller learning_rate to reduce instability #' bst <- xgb.train( -#' c(param, list(eta = 0.5)), +#' c(param, list(learning_rate = 0.5)), #' dtrain, #' evals = list(tr = dtrain), #' nrounds = 50, @@ -1044,7 +1052,7 @@ xgb.cb.cv.predict <- function(save_models = FALSE, outputmargin = FALSE) { #' #' # CV: #' bst <- xgb.cv( -#' c(param, list(eta = 0.5)), +#' c(param, list(learning_rate = 0.5)), #' dtrain, #' nfold = 5, #' nrounds = 70, diff --git a/R-package/R/utils.R b/R-package/R/utils.R index 81e15f7e4421..ab88ef5d58c1 100644 --- a/R-package/R/utils.R +++ b/R-package/R/utils.R @@ -493,7 +493,6 @@ NULL #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.Booster.R b/R-package/R/xgb.Booster.R index 6ffaa299b500..e424d14d96cb 100644 --- a/R-package/R/xgb.Booster.R +++ b/R-package/R/xgb.Booster.R @@ -267,7 +267,6 @@ xgb.get.handle <- function(object) { #' nrounds = 5, #' params = xgb.params( #' max_depth = 2, -#' eta = 0.5, #' nthread = nthread, #' objective = "binary:logistic" #' ) @@ -312,7 +311,6 @@ xgb.get.handle <- function(object) { #' nrounds = 10, #' params = xgb.params( #' max_depth = 4, -#' eta = 0.5, #' nthread = 2, #' subsample = 0.5, #' objective = "multi:softprob", @@ -336,7 +334,6 @@ xgb.get.handle <- function(object) { #' nrounds = 10, #' params = xgb.params( #' max_depth = 4, -#' eta = 0.5, #' nthread = 2, #' subsample = 0.5, #' objective = "multi:softmax", @@ -671,7 +668,6 @@ validate.features <- function(bst, newdata) { #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) @@ -779,7 +775,6 @@ xgb.attributes <- function(object) { #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) @@ -834,13 +829,13 @@ xgb.config <- function(object) { #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, +#' learning_rate = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) #' ) #' -#' xgb.model.parameters(bst) <- list(eta = 0.1) +#' xgb.model.parameters(bst) <- list(learning_rate = 0.1) #' #' @rdname xgb.model.parameters #' @export @@ -1281,7 +1276,6 @@ xgb.is.same.Booster <- function(obj1, obj2) { #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.create.features.R b/R-package/R/xgb.create.features.R index 85d9d560cef0..a175e087945f 100644 --- a/R-package/R/xgb.create.features.R +++ b/R-package/R/xgb.create.features.R @@ -52,7 +52,7 @@ #' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2)) #' dtest <- with(agaricus.test, xgb.DMatrix(data, label = label, nthread = 2)) #' -#' param <- list(max_depth = 2, eta = 1, objective = 'binary:logistic', nthread = 1) +#' param <- list(max_depth = 2, learning_rate = 1, objective = 'binary:logistic', nthread = 1) #' nrounds = 4 #' #' bst <- xgb.train(params = param, data = dtrain, nrounds = nrounds) diff --git a/R-package/R/xgb.cv.R b/R-package/R/xgb.cv.R index 9b4095150117..2e22c1afc5ff 100644 --- a/R-package/R/xgb.cv.R +++ b/R-package/R/xgb.cv.R @@ -96,7 +96,6 @@ #' params = xgb.params( #' nthread = 2, #' max_depth = 3, -#' eta = 1, #' objective = "binary:logistic" #' ), #' nfold = 5, @@ -316,7 +315,6 @@ xgb.cv <- function(params = xgb.params(), data, nrounds, nfold, #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.dump.R b/R-package/R/xgb.dump.R index cf601e6388c1..3560bf5dd180 100644 --- a/R-package/R/xgb.dump.R +++ b/R-package/R/xgb.dump.R @@ -34,7 +34,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.importance.R b/R-package/R/xgb.importance.R index c1b45e81bb8c..d75d641a56f8 100644 --- a/R-package/R/xgb.importance.R +++ b/R-package/R/xgb.importance.R @@ -49,7 +49,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) @@ -63,7 +62,7 @@ #' nrounds = 20, #' params = xgb.params( #' booster = "gblinear", -#' eta = 0.3, +#' learning_rate = 0.3, #' nthread = 1, #' objective = "binary:logistic" #' ) @@ -82,7 +81,6 @@ #' nrounds = nrounds, #' params = xgb.params( #' max_depth = 3, -#' eta = 0.2, #' nthread = 2, #' objective = "multi:softprob", #' num_class = nclass @@ -112,7 +110,7 @@ #' nrounds = 15, #' params = xgb.params( #' booster = "gblinear", -#' eta = 0.2, +#' learning_rate = 0.2, #' nthread = 1, #' objective = "multi:softprob", #' num_class = nclass diff --git a/R-package/R/xgb.load.R b/R-package/R/xgb.load.R index b08a308a3dd8..1d7da333319b 100644 --- a/R-package/R/xgb.load.R +++ b/R-package/R/xgb.load.R @@ -35,7 +35,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.model.dt.tree.R b/R-package/R/xgb.model.dt.tree.R index 12ed705ba8f7..d176c96ace3d 100644 --- a/R-package/R/xgb.model.dt.tree.R +++ b/R-package/R/xgb.model.dt.tree.R @@ -46,7 +46,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.plot.importance.R b/R-package/R/xgb.plot.importance.R index 750f386dd6f2..8acec15a0dd5 100644 --- a/R-package/R/xgb.plot.importance.R +++ b/R-package/R/xgb.plot.importance.R @@ -55,7 +55,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 3, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.plot.multi.trees.R b/R-package/R/xgb.plot.multi.trees.R index 1c57dd84babd..5b6764a6fdb4 100644 --- a/R-package/R/xgb.plot.multi.trees.R +++ b/R-package/R/xgb.plot.multi.trees.R @@ -40,7 +40,7 @@ #' verbose = 0, #' params = xgb.params( #' max_depth = 15, -#' eta = 1, +#' learning_rate = 1, #' nthread = nthread, #' objective = "binary:logistic", #' min_child_weight = 50 diff --git a/R-package/R/xgb.plot.shap.R b/R-package/R/xgb.plot.shap.R index bb678968db88..5b0661dfea4b 100644 --- a/R-package/R/xgb.plot.shap.R +++ b/R-package/R/xgb.plot.shap.R @@ -86,7 +86,7 @@ #' nrounds = nrounds, #' verbose = 0, #' params = xgb.params( -#' eta = 0.1, +#' learning_rate = 0.1, #' max_depth = 3, #' subsample = 0.5, #' objective = "binary:logistic", @@ -114,7 +114,6 @@ #' verbose = 0, #' params = xgb.params( #' max_depth = 2, -#' eta = 0.3, #' subsample = 0.5, #' nthread = nthread, #' objective = "multi:softprob", diff --git a/R-package/R/xgb.plot.tree.R b/R-package/R/xgb.plot.tree.R index f18e17a9e1fe..86362f1c1659 100644 --- a/R-package/R/xgb.plot.tree.R +++ b/R-package/R/xgb.plot.tree.R @@ -44,7 +44,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 3, -#' eta = 1, #' nthread = 2, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.save.R b/R-package/R/xgb.save.R index 855cf964b37b..418b95f1d207 100644 --- a/R-package/R/xgb.save.R +++ b/R-package/R/xgb.save.R @@ -47,7 +47,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.save.raw.R b/R-package/R/xgb.save.raw.R index 3c10cd9f2a5b..bd960de55738 100644 --- a/R-package/R/xgb.save.raw.R +++ b/R-package/R/xgb.save.raw.R @@ -26,7 +26,6 @@ #' nrounds = 2, #' params = xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic" #' ) diff --git a/R-package/R/xgb.train.R b/R-package/R/xgb.train.R index 9fe8fb3c8f29..cd13d82b172e 100644 --- a/R-package/R/xgb.train.R +++ b/R-package/R/xgb.train.R @@ -150,7 +150,6 @@ #' ## A simple xgb.train example: #' param <- xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = "binary:logistic", #' eval_metric = "auc" @@ -176,7 +175,6 @@ #' # 'eval_metric' parameters in the params list: #' param <- xgb.params( #' max_depth = 2, -#' eta = 1, #' nthread = nthread, #' objective = logregobj, #' eval_metric = evalerror @@ -194,12 +192,12 @@ #' ## An xgb.train example of using variable learning rates at each iteration: #' param <- xgb.params( #' max_depth = 2, -#' eta = 1, +#' learning_rate = 1, #' nthread = nthread, #' objective = "binary:logistic", #' eval_metric = "auc" #' ) -#' my_etas <- list(eta = c(0.5, 0.1)) +#' my_learning_rates <- list(learning_rate = c(0.5, 0.1)) #' #' bst <- xgb.train( #' param, @@ -207,7 +205,7 @@ #' nrounds = 2, #' evals = evals, #' verbose = 0, -#' callbacks = list(xgb.cb.reset.parameters(my_etas)) +#' callbacks = list(xgb.cb.reset.parameters(my_learning_rates)) #' ) #' #' ## Early stopping: diff --git a/R-package/man/a-compatibility-note-for-saveRDS-save.Rd b/R-package/man/a-compatibility-note-for-saveRDS-save.Rd index c4e9026d77f3..5820cd3acf5e 100644 --- a/R-package/man/a-compatibility-note-for-saveRDS-save.Rd +++ b/R-package/man/a-compatibility-note-for-saveRDS-save.Rd @@ -85,7 +85,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/predict.xgb.Booster.Rd b/R-package/man/predict.xgb.Booster.Rd index 2ef3f1b4bf61..ee0307bf3f47 100644 --- a/R-package/man/predict.xgb.Booster.Rd +++ b/R-package/man/predict.xgb.Booster.Rd @@ -226,7 +226,6 @@ bst <- xgb.train( nrounds = 5, params = xgb.params( max_depth = 2, - eta = 0.5, nthread = nthread, objective = "binary:logistic" ) @@ -271,7 +270,6 @@ bst <- xgb.train( nrounds = 10, params = xgb.params( max_depth = 4, - eta = 0.5, nthread = 2, subsample = 0.5, objective = "multi:softprob", @@ -295,7 +293,6 @@ bst <- xgb.train( nrounds = 10, params = xgb.params( max_depth = 4, - eta = 0.5, nthread = 2, subsample = 0.5, objective = "multi:softmax", diff --git a/R-package/man/print.xgb.Booster.Rd b/R-package/man/print.xgb.Booster.Rd index e797bd60f6d4..e70e9f622f1a 100644 --- a/R-package/man/print.xgb.Booster.Rd +++ b/R-package/man/print.xgb.Booster.Rd @@ -26,7 +26,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/print.xgb.cv.Rd b/R-package/man/print.xgb.cv.Rd index a8c1d70ef4a7..80e67e8ffb23 100644 --- a/R-package/man/print.xgb.cv.Rd +++ b/R-package/man/print.xgb.cv.Rd @@ -30,7 +30,6 @@ cv <- xgb.cv( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.attr.Rd b/R-package/man/xgb.attr.Rd index 015da9458b9b..36a570f1732f 100644 --- a/R-package/man/xgb.attr.Rd +++ b/R-package/man/xgb.attr.Rd @@ -69,7 +69,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.cb.gblinear.history.Rd b/R-package/man/xgb.cb.gblinear.history.Rd index a5c6cd17a011..c8586bf23c90 100644 --- a/R-package/man/xgb.cb.gblinear.history.Rd +++ b/R-package/man/xgb.cb.gblinear.history.Rd @@ -63,17 +63,17 @@ param <- xgb.params( booster = "gblinear", objective = "reg:logistic", eval_metric = "auc", - lambda = 0.0003, - alpha = 0.0003, + reg_lambda = 0.0003, + reg_alpha = 0.0003, nthread = nthread ) -# For 'shotgun', which is a default linear updater, using high eta values may result in +# For 'shotgun', which is a default linear updater, using high learning_rate values may result in # unstable behaviour in some datasets. With this simple dataset, however, the high learning # rate does not break the convergence, but allows us to illustrate the typical pattern of # "stochastic explosion" behaviour of this lock-free algorithm at early boosting iterations. bst <- xgb.train( - c(param, list(eta = 1.)), + c(param, list(learning_rate = 1.)), dtrain, evals = list(tr = dtrain), nrounds = 200, @@ -90,7 +90,7 @@ bst <- xgb.train( c( param, xgb.params( - eta = 0.8, + learning_rate = 0.8, updater = "coord_descent", feature_selector = "thrifty", top_k = 1 @@ -103,12 +103,20 @@ bst <- xgb.train( ) matplot(xgb.gblinear.history(bst), type = "l") # Componentwise boosting is known to have similar effect to Lasso regularization. -# Try experimenting with various values of top_k, eta, nrounds, +# Try experimenting with various values of top_k, learning_rate, nrounds, # as well as different feature_selectors. # For xgb.cv: bst <- xgb.cv( - c(param, list(eta = 0.8)), + c( + param, + xgb.params( + learning_rate = 0.8, + updater = "coord_descent", + feature_selector = "thrifty", + top_k = 1 + ) + ), dtrain, nfold = 5, nrounds = 100, @@ -125,15 +133,15 @@ param <- xgb.params( booster = "gblinear", objective = "multi:softprob", num_class = 3, - lambda = 0.0003, - alpha = 0.0003, + reg_lambda = 0.0003, + reg_alpha = 0.0003, nthread = nthread ) # For the default linear updater 'shotgun' it sometimes is helpful -# to use smaller eta to reduce instability +# to use smaller learning_rate to reduce instability bst <- xgb.train( - c(param, list(eta = 0.5)), + c(param, list(learning_rate = 0.5)), dtrain, evals = list(tr = dtrain), nrounds = 50, @@ -147,7 +155,7 @@ matplot(xgb.gblinear.history(bst, class_index = 2), type = "l") # CV: bst <- xgb.cv( - c(param, list(eta = 0.5)), + c(param, list(learning_rate = 0.5)), dtrain, nfold = 5, nrounds = 70, diff --git a/R-package/man/xgb.config.Rd b/R-package/man/xgb.config.Rd index 12c23d2b29dd..1d199e8302d8 100644 --- a/R-package/man/xgb.config.Rd +++ b/R-package/man/xgb.config.Rd @@ -40,7 +40,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.create.features.Rd b/R-package/man/xgb.create.features.Rd index ebb210435b43..1d6038df4436 100644 --- a/R-package/man/xgb.create.features.Rd +++ b/R-package/man/xgb.create.features.Rd @@ -62,7 +62,7 @@ data(agaricus.test, package = "xgboost") dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2)) dtest <- with(agaricus.test, xgb.DMatrix(data, label = label, nthread = 2)) -param <- list(max_depth = 2, eta = 1, objective = 'binary:logistic', nthread = 1) +param <- list(max_depth = 2, learning_rate = 1, objective = 'binary:logistic', nthread = 1) nrounds = 4 bst <- xgb.train(params = param, data = dtrain, nrounds = nrounds) diff --git a/R-package/man/xgb.cv.Rd b/R-package/man/xgb.cv.Rd index 02a1a876b6a9..855781c0e53a 100644 --- a/R-package/man/xgb.cv.Rd +++ b/R-package/man/xgb.cv.Rd @@ -200,7 +200,6 @@ cv <- xgb.cv( params = xgb.params( nthread = 2, max_depth = 3, - eta = 1, objective = "binary:logistic" ), nfold = 5, diff --git a/R-package/man/xgb.dump.Rd b/R-package/man/xgb.dump.Rd index a3b622947eac..d10c61c46777 100644 --- a/R-package/man/xgb.dump.Rd +++ b/R-package/man/xgb.dump.Rd @@ -61,7 +61,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.importance.Rd b/R-package/man/xgb.importance.Rd index f26067d7fef9..fe648cf8a639 100644 --- a/R-package/man/xgb.importance.Rd +++ b/R-package/man/xgb.importance.Rd @@ -75,7 +75,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, objective = "binary:logistic" ) @@ -89,7 +88,7 @@ bst <- xgb.train( nrounds = 20, params = xgb.params( booster = "gblinear", - eta = 0.3, + learning_rate = 0.3, nthread = 1, objective = "binary:logistic" ) @@ -108,7 +107,6 @@ mbst <- xgb.train( nrounds = nrounds, params = xgb.params( max_depth = 3, - eta = 0.2, nthread = 2, objective = "multi:softprob", num_class = nclass @@ -138,7 +136,7 @@ mbst <- xgb.train( nrounds = 15, params = xgb.params( booster = "gblinear", - eta = 0.2, + learning_rate = 0.2, nthread = 1, objective = "multi:softprob", num_class = nclass diff --git a/R-package/man/xgb.load.Rd b/R-package/man/xgb.load.Rd index 3059d530b017..ef546a30a178 100644 --- a/R-package/man/xgb.load.Rd +++ b/R-package/man/xgb.load.Rd @@ -41,7 +41,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.model.dt.tree.Rd b/R-package/man/xgb.model.dt.tree.Rd index f55fc17a4e7b..d3c8c442d1b7 100644 --- a/R-package/man/xgb.model.dt.tree.Rd +++ b/R-package/man/xgb.model.dt.tree.Rd @@ -73,7 +73,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.model.parameters.Rd b/R-package/man/xgb.model.parameters.Rd index 5f7c11a1eb95..53c0b60ca81b 100644 --- a/R-package/man/xgb.model.parameters.Rd +++ b/R-package/man/xgb.model.parameters.Rd @@ -39,12 +39,12 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, + learning_rate = 1, nthread = 2, objective = "binary:logistic" ) ) -xgb.model.parameters(bst) <- list(eta = 0.1) +xgb.model.parameters(bst) <- list(learning_rate = 0.1) } diff --git a/R-package/man/xgb.plot.importance.Rd b/R-package/man/xgb.plot.importance.Rd index 7b9dc40d2450..78ed27a22238 100644 --- a/R-package/man/xgb.plot.importance.Rd +++ b/R-package/man/xgb.plot.importance.Rd @@ -93,7 +93,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 3, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.plot.multi.trees.Rd b/R-package/man/xgb.plot.multi.trees.Rd index 989096e60e42..acea6ccd2d1b 100644 --- a/R-package/man/xgb.plot.multi.trees.Rd +++ b/R-package/man/xgb.plot.multi.trees.Rd @@ -74,7 +74,7 @@ bst <- xgb.train( verbose = 0, params = xgb.params( max_depth = 15, - eta = 1, + learning_rate = 1, nthread = nthread, objective = "binary:logistic", min_child_weight = 50 diff --git a/R-package/man/xgb.plot.shap.Rd b/R-package/man/xgb.plot.shap.Rd index 7bdd5ad2bfac..471b5092f75c 100644 --- a/R-package/man/xgb.plot.shap.Rd +++ b/R-package/man/xgb.plot.shap.Rd @@ -139,7 +139,7 @@ bst <- xgb.train( nrounds = nrounds, verbose = 0, params = xgb.params( - eta = 0.1, + learning_rate = 0.1, max_depth = 3, subsample = 0.5, objective = "binary:logistic", @@ -167,7 +167,6 @@ mbst <- xgb.train( verbose = 0, params = xgb.params( max_depth = 2, - eta = 0.3, subsample = 0.5, nthread = nthread, objective = "multi:softprob", diff --git a/R-package/man/xgb.plot.tree.Rd b/R-package/man/xgb.plot.tree.Rd index ebcc8603fe98..cafb8249c090 100644 --- a/R-package/man/xgb.plot.tree.Rd +++ b/R-package/man/xgb.plot.tree.Rd @@ -71,7 +71,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 3, - eta = 1, nthread = 2, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.save.Rd b/R-package/man/xgb.save.Rd index 738f947405c7..65667b23291b 100644 --- a/R-package/man/xgb.save.Rd +++ b/R-package/man/xgb.save.Rd @@ -55,7 +55,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.save.raw.Rd b/R-package/man/xgb.save.raw.Rd index 24f190a88c30..e881b9a7363f 100644 --- a/R-package/man/xgb.save.raw.Rd +++ b/R-package/man/xgb.save.raw.Rd @@ -37,7 +37,6 @@ bst <- xgb.train( nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic" ) diff --git a/R-package/man/xgb.train.Rd b/R-package/man/xgb.train.Rd index 2a2d45c78924..ba2f4a9d884e 100644 --- a/R-package/man/xgb.train.Rd +++ b/R-package/man/xgb.train.Rd @@ -187,7 +187,6 @@ evals <- list(train = dtrain, eval = dtest) ## A simple xgb.train example: param <- xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = "binary:logistic", eval_metric = "auc" @@ -213,7 +212,6 @@ evalerror <- function(preds, dtrain) { # 'eval_metric' parameters in the params list: param <- xgb.params( max_depth = 2, - eta = 1, nthread = nthread, objective = logregobj, eval_metric = evalerror @@ -231,12 +229,12 @@ bst <- xgb.train( ## An xgb.train example of using variable learning rates at each iteration: param <- xgb.params( max_depth = 2, - eta = 1, + learning_rate = 1, nthread = nthread, objective = "binary:logistic", eval_metric = "auc" ) -my_etas <- list(eta = c(0.5, 0.1)) +my_learning_rates <- list(learning_rate = c(0.5, 0.1)) bst <- xgb.train( param, @@ -244,7 +242,7 @@ bst <- xgb.train( nrounds = 2, evals = evals, verbose = 0, - callbacks = list(xgb.cb.reset.parameters(my_etas)) + callbacks = list(xgb.cb.reset.parameters(my_learning_rates)) ) ## Early stopping: diff --git a/R-package/tests/testthat/test_basic.R b/R-package/tests/testthat/test_basic.R index fdec78e88083..a12a30a0eeec 100644 --- a/R-package/tests/testthat/test_basic.R +++ b/R-package/tests/testthat/test_basic.R @@ -21,7 +21,7 @@ test_that("train and predict binary classification", { nrounds = nrounds, params = xgb.params( max_depth = 2, - eta = 1, + learning_rate = 1, nthread = n_threads, objective = "binary:logistic", eval_metric = "error" @@ -116,7 +116,7 @@ test_that("dart prediction works", { booster = "dart", rate_drop = 0.5, one_drop = TRUE, - eta = 1, + learning_rate = 1, nthread = n_threads, objective = "reg:squarederror" ) @@ -134,7 +134,7 @@ test_that("dart prediction works", { params = xgb.params( booster = "dart", max_depth = 2, - eta = 1, + learning_rate = 1, rate_drop = 0.5, one_drop = TRUE, nthread = n_threads, @@ -160,7 +160,7 @@ test_that("train and predict softprob", { data = xgb.DMatrix(as.matrix(iris[, -5]), label = lb), nrounds = 5, params = xgb.params( - max_depth = 3, eta = 0.5, nthread = n_threads, + max_depth = 3, learning_rate = 0.5, nthread = n_threads, objective = "multi:softprob", num_class = 3, eval_metric = "merror" ), evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb)) @@ -219,7 +219,7 @@ test_that("train and predict softmax", { data = xgb.DMatrix(as.matrix(iris[, -5]), label = lb), nrounds = 5, params = xgb.params( - max_depth = 3, eta = 0.5, nthread = n_threads, + max_depth = 3, learning_rate = 0.5, nthread = n_threads, objective = "multi:softmax", num_class = 3, eval_metric = "merror" ), evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb)) @@ -273,10 +273,15 @@ test_that("train and predict RF with softprob", { nrounds = nrounds, verbose = 0, params = xgb.params( - max_depth = 3, eta = 0.9, nthread = n_threads, - objective = "multi:softprob", eval_metric = "merror", + max_depth = 3, + learning_rate = 0.9, + nthread = n_threads, + objective = "multi:softprob", + eval_metric = "merror", num_class = 3, - num_parallel_tree = 4, subsample = 0.5, colsample_bytree = 0.5 + num_parallel_tree = 4, + subsample = 0.5, + colsample_bytree = 0.5 ), evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb)) ) @@ -300,7 +305,7 @@ test_that("use of multiple eval metrics works", { nrounds = 2, params = list( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic", + learning_rate = 1, nthread = n_threads, objective = "binary:logistic", eval_metric = "error", eval_metric = "auc", eval_metric = "logloss" ), evals = list(train = xgb.DMatrix(train$data, label = train$label)) @@ -316,7 +321,9 @@ test_that("use of multiple eval metrics works", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic", + learning_rate = 1, + nthread = n_threads, + objective = "binary:logistic", eval_metric = list("error", "auc", "logloss") ), evals = list(train = xgb.DMatrix(train$data, label = train$label)) @@ -333,7 +340,7 @@ test_that("training continuation works", { dtrain <- xgb.DMatrix(train$data, label = train$label, nthread = n_threads) evals <- list(train = dtrain) params <- xgb.params( - objective = "binary:logistic", max_depth = 2, eta = 1, nthread = n_threads + objective = "binary:logistic", max_depth = 2, learning_rate = 1, nthread = n_threads ) # for the reference, use 4 iterations at once: @@ -375,7 +382,9 @@ test_that("xgb.cv works", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1., nthread = n_threads, objective = "binary:logistic", + learning_rate = 1., + nthread = n_threads, + objective = "binary:logistic", eval_metric = "error" ), verbose = TRUE @@ -402,7 +411,8 @@ test_that("xgb.cv works with stratified folds", { nfold = 5, params = xgb.params( max_depth = 2, - eta = 1., nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ), verbose = FALSE, stratified = FALSE ) @@ -413,7 +423,8 @@ test_that("xgb.cv works with stratified folds", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1., nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ), verbose = FALSE, stratified = TRUE ) @@ -429,7 +440,8 @@ test_that("train and predict with non-strict classes", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ), verbose = 0 ) @@ -444,7 +456,8 @@ test_that("train and predict with non-strict classes", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ), verbose = 0 ), @@ -462,7 +475,8 @@ test_that("train and predict with non-strict classes", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ), verbose = 0 ), @@ -485,7 +499,7 @@ test_that("max_delta_step works", { params <- xgb.params( objective = "binary:logistic", eval_metric = "logloss", max_depth = 2, nthread = n_threads, - eta = 0.5 + learning_rate = 0.5 ) nrounds <- 5 # model with no restriction on max_delta_step @@ -512,7 +526,7 @@ test_that("colsample_bytree works", { ## Use colsample_bytree = 0.01, so that roughly one out of 100 features is chosen for ## each tree params <- xgb.params( - max_depth = 2, eta = 0, nthread = n_threads, + max_depth = 2, learning_rate = 0, nthread = n_threads, colsample_bytree = 0.01, objective = "binary:logistic", eval_metric = "auc" ) @@ -530,7 +544,8 @@ test_that("Configuration works", { nrounds = 2, params = xgb.params( max_depth = 2, - eta = 1, nthread = n_threads, objective = "binary:logistic" + nthread = n_threads, + objective = "binary:logistic" ) ) config <- xgb.config(bst) diff --git a/R-package/tests/testthat/test_booster_slicing.R b/R-package/tests/testthat/test_booster_slicing.R index f80968e06476..d67e2f0b56ce 100644 --- a/R-package/tests/testthat/test_booster_slicing.R +++ b/R-package/tests/testthat/test_booster_slicing.R @@ -5,7 +5,7 @@ dm <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label, nthread = 1 # Note: here need large step sizes in order for the predictions # to have substantially different leaf assignments on each tree model <- xgb.train( - params = list(objective = "binary:logistic", nthread = 1, max_depth = 4, eta = 0.5), + params = xgb.params(objective = "binary:logistic", nthread = 1, max_depth = 4), data = dm, nrounds = 20 ) diff --git a/R-package/tests/testthat/test_callbacks.R b/R-package/tests/testthat/test_callbacks.R index 7eef3cb46aa9..43fe56576d81 100644 --- a/R-package/tests/testthat/test_callbacks.R +++ b/R-package/tests/testthat/test_callbacks.R @@ -168,41 +168,41 @@ test_that("can store evaluation_log without printing", { test_that("xgb.cb.reset.parameters works as expected", { - # fixed eta - params <- c(params, list(eta = 0.9)) + # fixed learning_rate + params <- c(params, list(learning_rate = 0.9)) set.seed(111) bst0 <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0) expect_false(is.null(attributes(bst0)$evaluation_log)) expect_false(is.null(attributes(bst0)$evaluation_log$train_error)) - # same eta but re-set as a vector parameter in the callback + # same learning_rate but re-set as a vector parameter in the callback set.seed(111) - my_par <- list(eta = c(0.9, 0.9)) + my_par <- list(learning_rate = c(0.9, 0.9)) bst1 <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0, callbacks = list(xgb.cb.reset.parameters(my_par))) expect_false(is.null(attributes(bst1)$evaluation_log$train_error)) expect_equal(attributes(bst0)$evaluation_log$train_error, attributes(bst1)$evaluation_log$train_error) - # same eta but re-set via a function in the callback + # same learning_rate but re-set via a function in the callback set.seed(111) - my_par <- list(eta = function(itr, itr_end) 0.9) + my_par <- list(learning_rate = function(itr, itr_end) 0.9) bst2 <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0, callbacks = list(xgb.cb.reset.parameters(my_par))) expect_false(is.null(attributes(bst2)$evaluation_log$train_error)) expect_equal(attributes(bst0)$evaluation_log$train_error, attributes(bst2)$evaluation_log$train_error) - # different eta re-set as a vector parameter in the callback + # different learning_rate re-set as a vector parameter in the callback set.seed(111) - my_par <- list(eta = c(0.6, 0.5)) + my_par <- list(learning_rate = c(0.6, 0.5)) bst3 <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0, callbacks = list(xgb.cb.reset.parameters(my_par))) expect_false(is.null(attributes(bst3)$evaluation_log$train_error)) expect_false(all(attributes(bst0)$evaluation_log$train_error == attributes(bst3)$evaluation_log$train_error)) # resetting multiple parameters at the same time runs with no error - my_par <- list(eta = c(1., 0.5), gamma = c(1, 2), max_depth = c(4, 8)) + my_par <- list(learning_rate = c(1., 0.5), min_split_loss = c(1, 2), max_depth = c(4, 8)) expect_error( bst4 <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0, callbacks = list(xgb.cb.reset.parameters(my_par))) @@ -214,7 +214,7 @@ test_that("xgb.cb.reset.parameters works as expected", { , NA) # NA = no error # expect no learning with 0 learning rate - my_par <- list(eta = c(0., 0.)) + my_par <- list(learning_rate = c(0., 0.)) bstX <- xgb.train(params, dtrain, nrounds = 2, evals = evals, verbose = 0, callbacks = list(xgb.cb.reset.parameters(my_par))) expect_false(is.null(attributes(bstX)$evaluation_log$train_error)) @@ -255,7 +255,7 @@ test_that("xgb.cb.save.model works as expected", { }) test_that("early stopping xgb.train works", { - params <- c(params, list(eta = 0.3)) + params <- c(params, list(learning_rate = 0.3)) set.seed(11) expect_output( bst <- xgb.train(params, dtrain, nrounds = 20, evals = evals, @@ -292,7 +292,7 @@ test_that("early stopping using a specific metric works", { c( within(params, rm("eval_metric")), list( - eta = 0.6, + learning_rate = 0.6, eval_metric = "logloss", eval_metric = "auc" ) @@ -347,7 +347,7 @@ test_that("early stopping xgb.cv works", { expect_output( { cv <- xgb.cv( - c(params, list(eta = 0.3)), + c(params, list(learning_rate = 0.3)), dtrain, nfold = 5, nrounds = 20, @@ -364,7 +364,7 @@ test_that("early stopping xgb.cv works", { }) test_that("prediction in xgb.cv works", { - params <- c(params, list(eta = 0.5)) + params <- c(params, list(learning_rate = 0.5)) set.seed(11) nrounds <- 4 cv <- xgb.cv(params, dtrain, nfold = 5, nrounds = nrounds, prediction = TRUE, verbose = 0) @@ -386,7 +386,12 @@ test_that("prediction in xgb.cv works", { test_that("prediction in xgb.cv works for gblinear too", { set.seed(11) - p <- xgb.params(booster = 'gblinear', objective = "reg:logistic", eta = 0.5, nthread = n_threads) + p <- xgb.params( + booster = 'gblinear', + objective = "reg:logistic", + learning_rate = 0.5, + nthread = n_threads + ) cv <- xgb.cv(p, dtrain, nfold = 5, nrounds = 2, prediction = TRUE, verbose = 0) expect_false(is.null(cv$evaluation_log)) expect_false(is.null(cv$cv_predict$pred)) @@ -394,7 +399,7 @@ test_that("prediction in xgb.cv works for gblinear too", { }) test_that("prediction in early-stopping xgb.cv works", { - params <- c(params, list(eta = 0.1, base_score = 0.5)) + params <- c(params, list(learning_rate = 0.1, base_score = 0.5)) set.seed(11) expect_output( cv <- xgb.cv(params, dtrain, nfold = 5, nrounds = 20, @@ -425,9 +430,13 @@ test_that("prediction in xgb.cv for softprob works", { nfold = 4, nrounds = 5, params = xgb.params( - objective = "multi:softprob", num_class = 3, - eta = 0.5, max_depth = 3, nthread = n_threads, - subsample = 0.8, gamma = 2 + objective = "multi:softprob", + num_class = 3, + learning_rate = 0.5, + max_depth = 3, + nthread = n_threads, + subsample = 0.8, + min_split_loss = 2 ), verbose = 0, prediction = TRUE diff --git a/R-package/tests/testthat/test_custom_objective.R b/R-package/tests/testthat/test_custom_objective.R index 1d08b8ebf280..7c1dff8eb86b 100644 --- a/R-package/tests/testthat/test_custom_objective.R +++ b/R-package/tests/testthat/test_custom_objective.R @@ -28,7 +28,7 @@ evalerror <- function(preds, dtrain) { return(list(metric = "error", value = err)) } -param <- list(max_depth = 2, eta = 1, nthread = n_threads, +param <- list(max_depth = 2, learning_rate = 1, nthread = n_threads, objective = logregobj, eval_metric = evalerror) num_round <- 2 diff --git a/R-package/tests/testthat/test_glm.R b/R-package/tests/testthat/test_glm.R index 226439319dc8..89fcd98ebe1e 100644 --- a/R-package/tests/testthat/test_glm.R +++ b/R-package/tests/testthat/test_glm.R @@ -13,7 +13,7 @@ test_that("gblinear works", { ) param <- list(objective = "binary:logistic", eval_metric = "error", booster = "gblinear", - nthread = n_threads, eta = 0.8, alpha = 0.0001, lambda = 0.0001) + nthread = n_threads, learning_rate = 0.8, reg_alpha = 0.0001, reg_lambda = 0.0001) evals <- list(eval = dtest, train = dtrain) n <- 5 # iterations @@ -63,7 +63,7 @@ test_that("gblinear early stopping works", { param <- xgb.params( objective = "binary:logistic", eval_metric = "error", booster = "gblinear", - nthread = n_threads, eta = 0.8, alpha = 0.0001, lambda = 0.0001, + nthread = n_threads, learning_rate = 0.8, reg_alpha = 0.0001, reg_lambda = 0.0001, updater = "coord_descent" ) diff --git a/R-package/tests/testthat/test_helpers.R b/R-package/tests/testthat/test_helpers.R index b03282cfd6d0..82b0279c4751 100644 --- a/R-package/tests/testthat/test_helpers.R +++ b/R-package/tests/testthat/test_helpers.R @@ -30,8 +30,10 @@ if (isTRUE(VCD_AVAILABLE)) { nrounds = nrounds, verbose = 0, params = xgb.params( max_depth = 9, - eta = 1, nthread = 2, - objective = "binary:logistic", booster = "gbtree", + learning_rate = 1, + nthread = 2, + objective = "binary:logistic", + booster = "gbtree", base_score = 0.5 ) ) @@ -40,8 +42,10 @@ if (isTRUE(VCD_AVAILABLE)) { data = xgb.DMatrix(sparse_matrix, label = label), nrounds = nrounds, verbose = 0, params = xgb.params( - eta = 1, nthread = 1, - objective = "binary:logistic", booster = "gblinear", + learning_rate = 1, + nthread = 1, + objective = "binary:logistic", + booster = "gblinear", base_score = 0.5 ) ) @@ -61,7 +65,7 @@ mbst.Tree <- xgb.train( verbose = 0, nrounds = nrounds, params = xgb.params( - max_depth = 3, eta = 0.5, nthread = 2, + max_depth = 3, learning_rate = 0.5, nthread = 2, objective = "multi:softprob", num_class = nclass, base_score = 0 ) ) @@ -71,7 +75,7 @@ mbst.GLM <- xgb.train( verbose = 0, nrounds = nrounds, params = xgb.params( - booster = "gblinear", eta = 0.1, nthread = 1, + booster = "gblinear", learning_rate = 0.1, nthread = 1, objective = "multi:softprob", num_class = nclass, base_score = 0 ) ) @@ -101,9 +105,11 @@ test_that("xgb.dump works for gblinear", { data = xgb.DMatrix(sparse_matrix, label = label), nrounds = 1, params = xgb.params( - eta = 1, + learning_rate = 1, nthread = 2, - alpha = 2, objective = "binary:logistic", booster = "gblinear" + reg_alpha = 2, + objective = "binary:logistic", + booster = "gblinear" ) ) d.sp <- xgb.dump(bst.GLM.sp) @@ -420,7 +426,8 @@ test_that("xgb.model.dt.tree and xgb.importance work with a single split model", nrounds = 1, verbose = 0, params = xgb.params( max_depth = 1, - eta = 1, nthread = 2, + learning_rate = 1, + nthread = 2, objective = "binary:logistic" ) ) diff --git a/R-package/tests/testthat/test_interaction_constraints.R b/R-package/tests/testthat/test_interaction_constraints.R index d28f1e618d49..430b71a49bb4 100644 --- a/R-package/tests/testthat/test_interaction_constraints.R +++ b/R-package/tests/testthat/test_interaction_constraints.R @@ -18,7 +18,8 @@ test_that("interaction constraints for regression", { nrounds = 100, verbose = 0, params = xgb.params( max_depth = 3, - eta = 0.1, nthread = 2, + learning_rate = 0.1, + nthread = 2, interaction_constraints = list(c(0, 1)) ) ) diff --git a/R-package/tests/testthat/test_interactions.R b/R-package/tests/testthat/test_interactions.R index a01adcc532d4..1325e73e4ea2 100644 --- a/R-package/tests/testthat/test_interactions.R +++ b/R-package/tests/testthat/test_interactions.R @@ -21,8 +21,12 @@ test_that("predict feature interactions works", { y <- f_int(X) dm <- xgb.DMatrix(X, label = y, nthread = n_threads) - param <- list( - eta = 0.1, max_depth = 4, base_score = mean(y), lambda = 0, nthread = n_threads + param <- xgb.params( + learning_rate = 0.1, + max_depth = 4, + base_score = mean(y), + reg_lambda = 0, + nthread = n_threads ) b <- xgb.train(param, dm, 100) @@ -124,7 +128,11 @@ test_that("multiclass feature interactions work", { as.matrix(iris[, -5]), label = as.numeric(iris$Species) - 1, nthread = n_threads ) param <- xgb.params( - eta = 0.1, max_depth = 4, objective = 'multi:softprob', num_class = 3, nthread = n_threads + learning_rate = 0.1, + max_depth = 4, + objective = 'multi:softprob', + num_class = 3, + nthread = n_threads ) b <- xgb.train(param, dm, 40) pred <- predict(b, dm, outputmargin = TRUE) diff --git a/R-package/tests/testthat/test_monotone.R b/R-package/tests/testthat/test_monotone.R index 70d67ceb7e22..e637f10590a9 100644 --- a/R-package/tests/testthat/test_monotone.R +++ b/R-package/tests/testthat/test_monotone.R @@ -12,7 +12,8 @@ test_that("monotone constraints for regression", { nrounds = 100, verbose = 0, params = xgb.params( max_depth = 2, - eta = 0.1, nthread = 2, + learning_rate = 0.1, + nthread = 2, monotone_constraints = -1 ) ) diff --git a/R-package/tests/testthat/test_parameter_exposure.R b/R-package/tests/testthat/test_parameter_exposure.R index aacefe3a83ce..0d7c119090d0 100644 --- a/R-package/tests/testthat/test_parameter_exposure.R +++ b/R-package/tests/testthat/test_parameter_exposure.R @@ -16,7 +16,7 @@ bst <- xgb.train( nrounds = 10, params = xgb.params( max_depth = 2, - eta = 1, + learning_rate = 1, nthread = 1, objective = "binary:logistic" ) @@ -30,7 +30,7 @@ test_that("call is exposed to R", { test_that("params is exposed to R", { model_params <- attributes(bst)$params expect_is(model_params, "list") - expect_equal(model_params$eta, 1) + expect_equal(model_params$learning_rate, 1) expect_equal(model_params$max_depth, 2) expect_equal(model_params$objective, "binary:logistic") }) diff --git a/R-package/tests/testthat/test_poisson_regression.R b/R-package/tests/testthat/test_poisson_regression.R index c045091d044b..c4caa7644a93 100644 --- a/R-package/tests/testthat/test_poisson_regression.R +++ b/R-package/tests/testthat/test_poisson_regression.R @@ -22,7 +22,7 @@ test_that("Poisson regression is centered around mean", { x <- matrix(rnorm(m * n), nrow = m) model <- xgb.train( data = xgb.DMatrix(x, label = y), - params = xgb.params(objective = "count:poisson", gamma = 1e4), + params = xgb.params(objective = "count:poisson", min_split_loss = 1e4), nrounds = 1 ) model_json <- xgb.save.raw(model, "json") |> rawToChar() |> jsonlite::fromJSON() @@ -42,7 +42,7 @@ test_that("Poisson regression is centered around mean", { w <- y + 1 model_weighted <- xgb.train( data = xgb.DMatrix(x, label = y, weight = w), - params = xgb.params(objective = "count:poisson", gamma = 1e4), + params = xgb.params(objective = "count:poisson", min_split_loss = 1e4), nrounds = 1 ) model_json <- xgb.save.raw(model_weighted, "json") |> rawToChar() |> jsonlite::fromJSON() diff --git a/R-package/tests/testthat/test_ranking.R b/R-package/tests/testthat/test_ranking.R index 3a87bc60944b..a7a55434a2fc 100644 --- a/R-package/tests/testthat/test_ranking.R +++ b/R-package/tests/testthat/test_ranking.R @@ -13,8 +13,14 @@ test_that('Test ranking with unweighted data', { group <- c(5, 5, 5, 5) dtrain <- xgb.DMatrix(X, label = y, group = group, nthread = n_threads) - params <- list(eta = 1, tree_method = 'exact', objective = 'rank:pairwise', max_depth = 1, - eval_metric = 'auc', eval_metric = 'aucpr', nthread = n_threads) + params <- xgb.params( + learning_rate = 1, + tree_method = 'exact', + objective = 'rank:pairwise', + max_depth = 1, + eval_metric = c('auc', 'aucpr'), + nthread = n_threads + ) bst <- xgb.train(params, dtrain, nrounds = 10, evals = list(train = dtrain), verbose = 0) # Check if the metric is monotone increasing expect_true(all(diff(attributes(bst)$evaluation_log$train_auc) >= 0)) @@ -35,9 +41,13 @@ test_that('Test ranking with weighted data', { X, label = y, group = group, weight = weight, nthread = n_threads ) - params <- list( - eta = 1, tree_method = "exact", objective = "rank:pairwise", max_depth = 1, - eval_metric = "auc", eval_metric = "aucpr", nthread = n_threads + params <- xgb.params( + learning_rate = 1, + tree_method = "exact", + objective = "rank:pairwise", + max_depth = 1, + eval_metric = c("auc", "aucpr"), + nthread = n_threads ) bst <- xgb.train(params, dtrain, nrounds = 10, evals = list(train = dtrain), verbose = 0) # Check if the metric is monotone increasing diff --git a/R-package/tests/testthat/test_unicode.R b/R-package/tests/testthat/test_unicode.R index efdb32ac31f3..6f34350d4242 100644 --- a/R-package/tests/testthat/test_unicode.R +++ b/R-package/tests/testthat/test_unicode.R @@ -13,7 +13,7 @@ test_that("Can save and load models with Unicode paths", { nrounds = nrounds, params = xgb.params( max_depth = 2, - eta = 1, nthread = 2, + nthread = 2, objective = "binary:logistic" ) ) diff --git a/R-package/tests/testthat/test_update.R b/R-package/tests/testthat/test_update.R index 7fdc6eb84bb3..899fca880050 100644 --- a/R-package/tests/testthat/test_update.R +++ b/R-package/tests/testthat/test_update.R @@ -20,8 +20,11 @@ test_that("updating the model works", { evals <- list(train = dtrain, test = dtest) # no-subsampling - p1 <- list( - objective = "binary:logistic", max_depth = 2, eta = 0.05, nthread = n_threads, + p1 <- xgb.params( + objective = "binary:logistic", + max_depth = 2, + learning_rate = 0.05, + nthread = n_threads, updater = "grow_colmaker,prune" ) set.seed(11) @@ -116,9 +119,16 @@ test_that("updating works for multiclass & multitree", { as.matrix(iris[, -5]), label = as.numeric(iris$Species) - 1, nthread = n_threads ) evals <- list(train = dtr) - p0 <- list(max_depth = 2, eta = 0.5, nthread = n_threads, subsample = 0.6, - objective = "multi:softprob", num_class = 3, num_parallel_tree = 2, - base_score = 0) + p0 <- xgb.params( + max_depth = 2, + learning_rate = 0.5, + nthread = n_threads, + subsample = 0.6, + objective = "multi:softprob", + num_class = 3, + num_parallel_tree = 2, + base_score = 0 + ) set.seed(121) bst0 <- xgb.train(p0, dtr, 5, evals = evals, verbose = 0) tr0 <- xgb.model.dt.tree(model = bst0) diff --git a/R-package/tests/testthat/test_xgboost.R b/R-package/tests/testthat/test_xgboost.R index f3278cf37ea2..2e353e807c1d 100644 --- a/R-package/tests/testthat/test_xgboost.R +++ b/R-package/tests/testthat/test_xgboost.R @@ -595,7 +595,7 @@ test_that("Whole function works", { monotone_constraints = list(age = -1), nthreads = 1L, nrounds = 5L, - eta = 3 + learning_rate = 3 ) expect_equal( attributes(model)$params$objective, @@ -613,7 +613,7 @@ test_that("Whole function works", { "interaction_constraints" %in% names(attributes(model)$params) ) expect_equal( - attributes(model)$params$eta, + attributes(model)$params$learning_rate, 3 ) txt <- capture.output({ diff --git a/R-package/vignettes/discoverYourData.Rmd b/R-package/vignettes/discoverYourData.Rmd index ed82e3b8ce49..8574dfe15b3e 100644 --- a/R-package/vignettes/discoverYourData.Rmd +++ b/R-package/vignettes/discoverYourData.Rmd @@ -174,7 +174,7 @@ The code below is very usual. For more information, you can look at the document ```{r} bst <- xgboost(x = sparse_matrix, y = output_vector, - max_depth = 4, eta = 1, + max_depth = 4, learning_rate = 1, nthread = 2, nrounds = 10) ``` diff --git a/R-package/vignettes/xgboostPresentation.Rmd b/R-package/vignettes/xgboostPresentation.Rmd index 444f7ba96fa8..a3c61e3ab9ad 100644 --- a/R-package/vignettes/xgboostPresentation.Rmd +++ b/R-package/vignettes/xgboostPresentation.Rmd @@ -141,7 +141,7 @@ bstSparse <- xgboost( , y = factor(train$label, levels = c(0, 1)) , objective = "binary:logistic" , max_depth = 2 - , eta = 1 + , learning_rate = 1 , nrounds = 2 , nthread = 2 ) @@ -160,7 +160,7 @@ bstTrInterface <- xgb.train( , params = xgb.params( objective = "binary:logistic" , max_depth = 2 - , eta = 1 + , learning_rate = 1 , nthread = 2 ) , nrounds = 2 @@ -183,7 +183,7 @@ bstDense <- xgboost( x = as.matrix(train$data), y = factor(train$label, levels = c(0, 1)), max_depth = 2, - eta = 1, + learning_rate = 1, nthread = 2, nrounds = 2 ) @@ -200,7 +200,7 @@ bstDF <- xgboost( x = df_train, y = factor(train$label, levels = c(0, 1)), max_depth = 2, - eta = 1, + learning_rate = 1, nthread = 2, nrounds = 2 ) @@ -222,7 +222,7 @@ bst <- xgboost( x = train$data, y = factor(train$label, levels = c(0, 1)), max_depth = 2, - eta = 1, + learning_rate = 1, nthread = 2, objective = "binary:logistic", nrounds = 5, @@ -321,7 +321,7 @@ bst <- xgb.train( data = dtrain , params = list( max_depth = 2 - , eta = 1 + , learning_rate = 1 , nthread = 2 , objective = "binary:logistic" ) @@ -344,7 +344,7 @@ For a better understanding of the learning progression, you may want to have som bst <- xgb.train( data = dtrain , params = list( - eta = 1 + learning_rate = 1 , max_depth = 2 , nthread = 2 , objective = "binary:logistic" @@ -361,7 +361,7 @@ bst <- xgb.train( ### Linear boosting -Until now, all the learnings we have performed were based on boosting trees. **XGBoost** implements a second algorithm, based on linear boosting. The only difference with previous command is `booster = "gblinear"` parameter (and removing `eta` parameter). +Until now, all the learnings we have performed were based on boosting trees. **XGBoost** implements a second algorithm, based on linear boosting. The only difference with previous command is `booster = "gblinear"` parameter (and removing `learning_rate` parameter). ```{r linearBoosting, message=F, warning=F} bst <- xgb.train( @@ -398,7 +398,7 @@ bst <- xgb.train( data = dtrain2 , params = list( max_depth = 2 - , eta = 1 + , learning_rate = 1 , nthread = 2 , objective = "binary:logistic" )