2

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

John Smith
  • 51
  • 6

3 Answers3

3

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
TomKraljevic
  • 3,661
  • 11
  • 14
  • I'm getting stuck on something simple here regarding the command line? What directory do I need to run this from? My current working directory? Or a specific h2o folder? I get the following message: Error: Could not find or load main class hex.genmodel.tools.PrintMojo – runningbirds May 08 '18 at 17:21
  • "java -cp /path/to/your/h2o.jar". You need to know where your h2o.jar is. It will either be in the R or Python directory where the h2o package gets installed, or you can download it from h2oai.download -> H2O latest stable release -> Download H2O. – TomKraljevic May 08 '18 at 18:47
1

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

topchef
  • 19,091
  • 9
  • 63
  • 102
0

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