XGBoost Python API – accessing estimators?

Viewed 133

Scikit-learn's sklearn.ensemble.GradientBoostingClassifier (as well as other ensemble methods) stores its weak classifiers as a class attribute, in sklearn.ensemble.GradientBoostingClassifier.estimators_. I am trying the XGBoost package, but it seems there is no straightforward way to access the model's sub-estimators, if at all. Is there a roundabout way of accessing these estimators, or I have to modify the XGBoost codebase to store them in a class attribute variable (or if I should bite the bullet and defer to the scikit-learn implementation)?

1 Answers

Depending on your preferred output type, you can use the get_booster() method to get a list of strings of each booster (credit to this post).

Alternatively, you can use XGBoost's built-in plot_tree() method (documentation) to visualise each tree.

Related