I'm using pydot in order to draw graphs in python. I'd like to represent 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 leaves 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 fine but in larger trees it is messy internal nodes belonging to different branches are unified.
The simple code I'm using is:
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 creating different node objects than create the edges and than add it to the graph but it seems that pydot checks the node pool for nodes with the same name instead of creating a new one.
Any ideas? thanks!