4 Setting Parameters
XGBoost is configured by a set of string-keyed parameters — the objective, tree depth, learning rate, and so on. The Racket API lets you pass them in two complementary ways.
4.1 The #:params bundle
#:params takes a hash or association list of parameters. Keys may be strings, symbols, or keywords; symbol and keyword keys are normalized to XGBoost’s underscore style (hyphens become underscores), and values are converted to strings before reaching the native layer:
(train dtrain #:params '((objective . "reg:squarederror") (max-depth . 3) (eta . 0.1) (tree-method . "hist")))
Here 'max-depth reaches XGBoost as "max_depth", and the numeric 3 becomes "3".
4.2 Keyword conveniences
The most common parameters also have dedicated keywords on train: #:objective, #:eta, #:max-depth, #:num-class, #:eval-metric, and #:verbosity. They are applied after #:params, so a keyword overrides any same-named entry in the bundle:
(train dtrain #:objective "binary:logistic" #:max-depth 3 #:eta 0.3 #:verbosity 0 #:rounds 30)
4.3 Evaluation sets
To watch performance on held-out data during training, pass #:evals — a list of (cons name dmatrix) pairs. XGBoost reports each named metric per round, and the names you choose appear in the metric lines:
(train dtrain #:evals (list (cons "train" dtrain) (cons "eval" deval)) #:objective "reg:squarederror" #:eval-metric "rmse" #:rounds 30)
Driving the evaluation loop yourself — to log metrics or stop early — is covered in Training.
4.4 Updating a booster’s parameters
A parameter can also be set on an existing booster with booster-set-param!, which uses the same key/value coercion as #:params:
(booster-set-param! booster "tree_method" "hist")