jupyter error: can't view decision tree as png in random forest

Viewed 136

I am trying to look at my decision tree in Jupyter Notebook. I have installed graphviz (in anaconda cmd prompt) and pydot.

#taking one tree from the forest and saving it as an image
#!pip install graphviz
from sklearn.tree import export_graphviz
#!pip install pydot
import pydot 

#pulling out one tree from the forest
tree = rf.estimators_[5]

#export one image to a dot file
feature_list = list(feature.columns)
export_graphviz(tree, out_file = 'tree.dot', feature_names = feature_list, 
           rounded = True, precision = 1)

#use dot file to create a graph
(graph, ) = pydot.graph_from_dot_file('tree.dot')

#write graph to a png file
graph.write_png('tree.png')

The last line runs successfully without any output. I then run the code in anaconda command prompt: dot -Tpng tree.dot -o tree.png and get the error: Error: dot: can't open tree.dot1

I am using a windows machine.

1 Answers

The image was available in my downloads folder itself.

Related