On this page:
6.1 Choosing what to predict
6.2 In-place prediction
9.2

6 Prediction🔗ℹ

predict runs a trained booster over a DMatrix. By default it returns a list of predictions; pass #:as 'f32vector to get the raw f32vector? copied from XGBoost instead:

(require xgboost)
 
(define preds (predict booster dtrain))                 ; list of reals
(define vec   (predict booster dtrain #:as 'f32vector)) ; f32vector

For a "binary:logistic" model the values are class-1 probabilities; for "multi:softprob" the output has nrow×num-class entries (row-major), while "multi:softmax" yields one predicted class index per row.

6.1 Choosing what to predict🔗ℹ

#:output selects the kind of output. 'value (the default) is the final prediction; 'margin is the raw score before the logistic or softmax transform; 'leaf gives per-tree leaf indices; and 'contribs / 'approx-contribs / 'interactions / 'approx-interactions return SHAP-style feature attributions:

(predict booster dtrain #:output 'margin)
(predict booster dtrain #:output 'contribs)

#:iteration-end limits prediction to the first N boosting rounds (0, the default, means all of them) — useful for evaluating an early-stopping prefix without re-slicing the booster.

6.2 In-place prediction🔗ℹ

For serving, you often have a single batch of raw features and no reason to build a DMatrix first. The predict-from-dense, predict-from-csr, and predict-from-columnar variants predict directly from Racket data and accept the same #:output, #:iteration-end, and #:as keywords as predict:

; dense rows, shaped like make-dmatrix's data argument
(predict-from-dense booster features
                    #:nrow 8 #:ncol 3
                    #:missing -1.0
                    #:as 'f32vector)
 
; CSR triple: indptr, indices, values, ncol
(predict-from-csr booster indptr indices values 3
                  #:missing -1.0)
 
; one f32vector per column
(predict-from-columnar booster
                       (list (f32vector 1.0 2.0 3.0)
                             (f32vector 2.0 1.0 0.5)
                             (f32vector 0.5 1.5 0.0))
                       #:missing -1.0)

In-place prediction returns the same numbers as building a DMatrix and calling predict; it just skips the intermediate allocation.