1
votes

I have built a random-forest model with h2o. I am trying to plot it with h2otree. I am getting a TypeError: 'NoneType' object is not iterable

I can replicate the error. The class H2OTree calls a function __decode_categoricals(model, response['levels']) which iterates over reponse levels of type None.

from h2o.tree import H2OTree
first_tree = H2OTree(model = rf_model, tree_number = 0, tree_class = target_class_category)
#error replication
params = {"model": model.model_id,
                  "tree_number": 0,
                  "tree_class": target_class_category}


response = h2o.api(endpoint="GET /3/Tree", data=params)
for lvl_index in response['levels']:

    if len(lvl_index) >0: #error, 'NoneType' has no len()
        print('yes')
1

1 Answers

0
votes

If you want to visualize an H2O Tree you can use the Mojo Visualizer (documentation here) or see previous questions/posts on this:

How to visualize H2O Tree?

Visualizing H2O GBM and Random Forest MOJO Models Trees in Python