Zhirui Wang
Zhirui Wang

Reputation: 184

Visualize trees in H2O XGBoost model

I was looking at this answer to visualize the gradient boosting tree model in H2O, it says the method on GBM can be applied to XGBoost as well:
Finding contribution by each feature into making particular prediction by h2o ensemble model

http://docs.h2o.ai/h2o/latest-stable/h2o-docs/productionizing.html

But when I try to use the method it mentioned on H2O XGBoost MOJO, it fails.

I check the source code of hex.genmodel.tools.PrintMojo:https://github.com/h2oai/h2o-3/blob/master/h2o-genmodel/src/main/java/hex/genmodel/tools/PrintMojo.java

it seems like it can only work on randomforest and GBM models, but not XGBoost model.

Is there anyone who knows how to visualize trees in H2O XGBoost model? Thanks!

Upvotes: 0

Views: 1239

Answers (2)

btbbass
btbbass

Reputation: 145

I finally found the solution, that seem not documented for XGBoost, but it is indeed the same as for other trees-related algorithms.

Just run this command to generate the first 50 trees from your model:

for tn in {1..50}
do
   java -cp h2o-3.24.0.1/h2o.jar hex.genmodel.tools.PrintMojo --tree $tn -i <your mojo model> -o XGBOOST_$tn.gv
   dot -Tpng  XGBOOST_$tn.gv -o xgboost_$tn.png
done

Upvotes: 0

Lauren
Lauren

Reputation: 5778

This is a feature H2O is currently adding, you can track its progress here: https://0xdata.atlassian.net/browse/PUBDEV-5743.

Note that in the ticket there is a suggestion in the comments on how to visualize the trees with native xgboost.

Upvotes: 1

Related Questions