2
votes

By running the commands,

m <- h2o.getModel("depth_grid_model_4")
h2o.varimp(m)

I am able to view the model's performance as well as the variable importance.

How do I view the splits used in each tree of the GBM model?

Thanks

3
Please accept the answer below if it's addressed your question. Thanks!TomKraljevic

3 Answers

3
votes

There is a tool to create visualizations for H2O-3 MOJO models. See the full documentation here:


Use R to create and download a MOJO:

library(h2o)
h2o.init()
df <- h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip")
model <- h2o.gbm(model_id = "model",
                training_frame = df,
                x = c("Year", "Month", "DayofMonth", "DayOfWeek", "UniqueCarrier"),
                y = "IsDepDelayed",
                max_depth = 3,
                ntrees = 5)
h2o.download_mojo(model, getwd(), FALSE)

Run the PrintMojo tool (packaged inside h2o.jar) on the command line to make a .png file. You need to download the latest stable H2O-3 release from http://www.h2o.ai/download/ and run the PrintMojo tool from the command line.

# (For MacOS: brew install graphviz)
java -cp h2o.jar hex.genmodel.tools.PrintMojo --tree 0 -i model.zip -o model.gv
dot -Tpng model.gv -o model.png
open model.png
1
votes

New Tree API was added in H2O in 3.22.0.1. It lets you fetch trees into R/Python objects from any tree-based model in H2O (for details see here):

tree <- h2o.getModelTree(model = airlines.model, tree_number = 1, tree_class = "NO")

Having a tree representation from h2o in R plotting a tree explained here: Finally, You Can Plot H2O Decision Trees in R

0
votes

You can export the model as POJO with h2o.download_pojo() and then look at the full details of each tree in the file.