Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get hyperparameters of xgb.train in python

xgb.train is the low level API to train an xgboost model in Python.

  • When I use XGBClassifier, which is a wrapper and calls xgb.train when a model is trained, I can print the XGBClassifier object and the hyperparameters are printed.
  • When using xgb.train I have no idea how to check the parameters after training

Code:

bst = xgb.train(params, dtrain)
bst.params # does not work!
like image 846
gato Avatar asked Sep 14 '25 08:09

gato


1 Answers

The save_config method noted here can be used to create a string representation of the model's configuration. This can be converted to a dict:

import json

config = json.loads(bst.save_config())

The result is somewhat deeply nested, but the hyperparameters are found like this:

config['learner']['gradient_booster']['updater']['grow_colmaker']['train_param']

like image 165
sply88 Avatar answered Sep 16 '25 22:09

sply88