I am using pydot to draw graphs in python. I would like to introduce a decision tree, say, something like (a1, a2, a3 are attributes, and two classes are 0 and 1:
a1>3 / \ a2>10 a3>-7 / \ / \ 1 0 1 0
However, using pydot, only two sheets are created, and the tree looks like this (png attached):
a1>3 / \ a2>10 a3>-7 | X | 1 0
Now, in this simple case, the logic is beautiful, but in large trees these dirty internal nodes belonging to different branches are unified.
Simple code that I use:
import pydot graph = pydot.Dot(graph_type='graph') edge = pydot.Edge("a_1>3", "a_2>10") graph.add_edge(edge) edge = pydot.Edge("a_1>3", "a_3>-7") graph.add_edge(edge) edge = pydot.Edge("a_2>10", "1") graph.add_edge(edge) edge = pydot.Edge("a_2>10", "0") graph.add_edge(edge) edge = pydot.Edge("a_3>-7", "1") graph.add_edge(edge) edge = pydot.Edge("a_3>-7", "0") graph.add_edge(edge) graph.write_png('simpleTree.png')
I also tried to create different node objects than to create edges and then add it to the graph, but it seems that pydot is checking the node pool for nodes of the same name instead of creating a new one.
Any ideas? thanks!

python decision-tree pydot
Sciencefriction
source share