On this page:
<r18-require>
<r18-provide>
<r18-run>
<*>

2.21 Booster attributes🔗ℹ

A booster carries an arbitrary string→string attribute dictionary — handy for stamping a model with provenance. This example sets two attributes with booster-set-attr!, reads them back with booster-attr, lists the keys with booster-attr-names, then removes one with booster-delete-attr! (a missing key reads back as #f).

(require xgboost)

(provide run-example)

(define (run-example)
  (define b (make-booster))
  (booster-set-attr! b "owner" "racket")
  (booster-set-attr! b "purpose" "example")
  (define before-delete
    (hash 'owner (booster-attr b "owner")
          'purpose (booster-attr b "purpose")
          'names (sort (booster-attr-names b) string<?)))
  (booster-delete-attr! b "purpose")
  (hash 'before-delete before-delete
        'purpose-after-delete (booster-attr b "purpose")
        'names-after-delete (booster-attr-names b)))

The harness "test/18-booster-attrs.rkt" prints the attributes and asserts the round-trip and the post-delete state.

<*> ::=