2.16 DMatrix metadata
A DMatrix carries more than features: you can attach and read back feature names and types, ranking group boundaries, and labels. This example sets each on a small matrix and round-trips them. Note dmatrix-set-group! takes group sizes but dmatrix-group-ptr returns the cumulative offsets (so a single group of 2 reads back as '(0 2)).
<r14-require> ::=
(require ffi/vector xgboost)
<r14-provide> ::=
(provide run-example)
<r14-run> ::=
(define (run-example) (define dm (make-dmatrix (f32vector 1.0 2.0 3.0 4.0) #:nrow 2 #:ncol 2 #:missing -1.0)) (dmatrix-set-feature-names! dm '("height" "weight")) (dmatrix-set-feature-types! dm '("q" "q")) (dmatrix-set-group! dm '(2)) (dmatrix-set-label! dm (f32vector 0.25 0.75)) (hash 'feature-names (dmatrix-feature-names dm) 'feature-types (dmatrix-feature-types dm) 'group-ptr (dmatrix-group-ptr dm) 'labels (dmatrix-label dm)))
The harness "test/14-dmatrix-metadata.rkt" prints each field and asserts it round-trips.
<*> ::=