The main question is to find which leaf node each sample is classified. There are thousands of posts on using tree.apply
. I am well aware of this function, which returns the index of the leaf node.
Now, I would like to add the leaf index in the nodes of the graph (which I generate by using Graphviz).
Drawing the enumeration technique used for the indexes won't work. The decision tree that I am developing is quite big. Therefore, I need to be able to print the leaf index in the graph.
Another option that I am open to is to generate an array with all the leaf indexes (in the same order) of the leaf nodes of the decision tree. Any hint on how to do this?
There is a parameter node_ids
of the command export_graphviz
. When this parameter is set to True
, then the indexes are added on the label of the decision tree.