R: Plot trees from h2o.randomForest() and h2o.gbm()

最后都变了- 提交于 2019-11-30 05:05:49

I think it may be the solution you are looking for;

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)

Now download the latest stable h2o release from http://www.h2o.ai/download/ and run the PrintMojo tool from the command line.

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

More info: http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/index.html

New Tree API introduced in 3.22.0.1 (October 2018) changes the whole game of visualizing H2O trees. General workflow may look like this:

and detailed example with code can be found here: Finally, You Can Plot H2O Decision Trees in R.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!