0

I'm trying to create an image of a decision tree using the pydot function graph_from_dot_data. Everything works fine, but the resulting image has an empty node next to the root node. Reproducible example -

from sklearn.datasets import load_iris
from sklearn import tree
import pydot
from IPython.display import Image

clf = DecisionTreeClassifier()
iris = load_iris()

clf = clf.fit(iris.data, iris.target)
graph = graph_from_dot_data(export_graphviz(clf))

Image(graph[0].create_png())

enter image description here

How can I produce a decision tree image without an empty node next to the root node?

big parma
  • 337
  • 1
  • 13

1 Answers1

0

Try to find empty node in small tree like:

for n in graph.get_nodes():
    print(n)

I have an empty node called '"\\n"'.
After that you can remove empty node by name:

graph.del_node('"\\n"')