Skip to content

Commit

Permalink
[R] Prefer descriptive parameter names (#11102)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes authored Dec 15, 2024
1 parent 874a690 commit 543b57f
Show file tree
Hide file tree
Showing 54 changed files with 205 additions and 170 deletions.
32 changes: 20 additions & 12 deletions R-package/R/callbacks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ NULL
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand Down
10 changes: 2 additions & 8 deletions R-package/R/xgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#' )
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -671,7 +668,6 @@ validate.features <- function(bst, newdata) {
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand Down Expand Up @@ -779,7 +775,6 @@ xgb.attributes <- function(object) {
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1285,7 +1280,6 @@ xgb.is.same.Booster <- function(obj1, obj2) {
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand Down
2 changes: 1 addition & 1 deletion R-package/R/xgb.create.features.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions R-package/R/xgb.cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
#' params = xgb.params(
#' nthread = 2,
#' max_depth = 3,
#' eta = 1,
#' objective = "binary:logistic"
#' ),
#' nfold = 5,
Expand Down Expand Up @@ -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"
#' )
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.dump.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand Down
6 changes: 2 additions & 4 deletions R-package/R/xgb.importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand All @@ -61,7 +60,7 @@
#' nrounds = 20,
#' params = xgb.params(
#' booster = "gblinear",
#' eta = 0.3,
#' learning_rate = 0.3,
#' nthread = 1,
#' objective = "binary:logistic"
#' )
Expand All @@ -80,7 +79,6 @@
#' nrounds = nrounds,
#' params = xgb.params(
#' max_depth = 3,
#' eta = 0.2,
#' nthread = 2,
#' objective = "multi:softprob",
#' num_class = nclass
Expand Down Expand Up @@ -110,7 +108,7 @@
#' nrounds = 15,
#' params = xgb.params(
#' booster = "gblinear",
#' eta = 0.2,
#' learning_rate = 0.2,
#' nthread = 1,
#' objective = "multi:softprob",
#' num_class = nclass
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.load.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.model.dt.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.plot.importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 3,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down
2 changes: 1 addition & 1 deletion R-package/R/xgb.plot.multi.trees.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#' verbose = 0,
#' params = xgb.params(
#' max_depth = 15,
#' eta = 1,
#' learning_rate = 1,
#' nthread = nthread,
#' objective = "binary:logistic",
#' min_child_weight = 50
Expand Down
3 changes: 1 addition & 2 deletions R-package/R/xgb.plot.shap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -114,7 +114,6 @@
#' verbose = 0,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 0.3,
#' subsample = 0.5,
#' nthread = nthread,
#' objective = "multi:softprob",
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.plot.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 3,
#' eta = 1,
#' nthread = 2,
#' objective = "binary:logistic"
#' )
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.save.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down
1 change: 0 additions & 1 deletion R-package/R/xgb.save.raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#' nrounds = 2,
#' params = xgb.params(
#' max_depth = 2,
#' eta = 1,
#' nthread = nthread,
#' objective = "binary:logistic"
#' )
Expand Down
8 changes: 3 additions & 5 deletions R-package/R/xgb.train.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -194,20 +192,20 @@
#' ## 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,
#' dtrain,
#' 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:
Expand Down
1 change: 0 additions & 1 deletion R-package/man/a-compatibility-note-for-saveRDS-save.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions R-package/man/predict.xgb.Booster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion R-package/man/print.xgb.Booster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion R-package/man/print.xgb.cv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion R-package/man/xgb.attr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 543b57f

Please sign in to comment.