Reputation: 47
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
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
install graphViz: https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224
install java JDK 14: https://www.oracle.com/java/technologies/javase/jdk14-archive-downloads.html
add Java to PATH environment variable (to be able to execute from console)
Compile H2O model in python and export model with the .download_mojo(path) function:
decTreeModel.download_mojo('C:/User/L/mojoExports/myMojoModel.zip')
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
dot -Tpng model.gv -o model.png
Upvotes: 1
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