pythonxgboostxgbclassifier

How to get hyperparameters of xgb.train in python


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

Code:

bst = xgb.train(params, dtrain)
bst.params # does not work!

Solution

  • 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']