我有df data_categorical
和一个模型model
。
我用
将df转换为h2o帧
data = h2o.H2OFrame(data_categorical)
并用
训练了我的模型model = H2ORandomForestEstimator(ntrees=1, max_depth=20, nfolds=10)
# Train model
model.train(x=training_columns, y=response_column, training_frame=train)
我正在尝试可视化所创建的树(请注意,我只需要一棵树),但是我似乎做不到。
我用
下载了mojo文件
model.download_mojo(path,get_genmodel_jar=True)
但是我不知道下一步该怎么做
答案 0 :(得分:1)
您可以使用以下文档中描述的工作流程:
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
答案 1 :(得分:1)
对于 Windows/python 用户,我整理了一个小食谱,包括所有步骤的链接:
一般信息: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/mojo-quickstart.html
安装graphViz: https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224
安装 Java JDK 14: https://www.oracle.com/java/technologies/javase/jdk14-archive-downloads.html
将 Java 添加到 PATH 环境变量(以便能够从控制台执行)
在 python 中编译 H2O 模型并使用 .download_mojo(path) 函数导出模型:
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