welo121
welo121

Reputation: 47

How to visualize H2O Tree?

I have df data_categorical and a model model.
I converted my df to h2o frame with
data = h2o.H2OFrame(data_categorical)

and trained my model with

model = H2ORandomForestEstimator(ntrees=1, max_depth=20, nfolds=10)
# Train model
model.train(x=training_columns, y=response_column, training_frame=train) 

I'm trying to visualize the tree that is created (note that I only need one tree) but I can't seem to do that.
I downloaded the mojo file with
model.download_mojo(path,get_genmodel_jar=True)
But I don't know what to do next

Upvotes: 0

Views: 2335

Answers (2)

Len
Len

Reputation: 11

For Windows/python users I put together a small recipe including links for all steps:

General info: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/mojo-quickstart.html

  1. install graphViz: https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224

  2. install java JDK 14: https://www.oracle.com/java/technologies/javase/jdk14-archive-downloads.html

  3. add Java to PATH environment variable (to be able to execute from console)

  4. Compile H2O model in python and export model with the .download_mojo(path) function:

decTreeModel.download_mojo('C:/User/L/mojoExports/myMojoModel.zip')

  1. Go to location of the myMojoModel.zip and start CMD in this directory.In CMD type:

java -cp h2o.jar hex.genmodel.tools.PrintMojo --tree 0 --levels 21 --title "title for tree" -i myMojoModel.zip -o model.gv -f 20 -d 3

meaning of parameters:

--tree n        : n is the number of the tree to be exported if there are more than one model in the mojo model (e.g. when using cross validation)

--levels n      : n is number of categorical levels to be printed (default 10)

--title "string"    : you can specify the title here

-i "path"       : "path" is path to input model (myMojoModel.zip)

-o "path"       : "path" is path to output graph (model.gv)

-f n            : n is the font size

-d n            : n is the number of decimals displayed for numbers
  1. in CMD, create the .png with graphViz. Type

dot -Tpng model.gv -o model.png

  1. it will create a .png in that directory which you can view with any png viewer

Upvotes: 1

TomKraljevic
TomKraljevic

Reputation: 3671

You can use the workflow described in the documentation below:

java -cp h2o.jar hex.genmodel.tools.PrintMojo --tree 0 -i model.zip -o model.gv -f 20 -d 3
dot -Tpng model.gv -o model.png
open model.png

Upvotes: 1

Related Questions