0

am trying to create a graph version of a scikit-learn decision tree model. My goal is to visualize it and eventually save it as a .png file (.jpeg could work too). Based on this website - https://medium.com/@rnbrown/creating-and-visualizing-decision-trees-with-python-f8e8fa394176- I wrote the code below using pydot. It gives the error below, and I am wondering if anyone knows how to address this.

from sklearn.externals.six import StringIO  
from IPython.display import Image  
from sklearn.tree import export_graphviz
import pydotplus
dot_data = StringIO()
export_graphviz(dtree, out_file=dot_data,  
                filled=True, rounded=True,
                special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())

InvocationException                       Traceback (most recent call last)
<ipython-input-45-0305e90704a1> in <module>()
     10                 special_characters=True)
     11 graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
---> 12 Image(graph.create_png())

C:\ProgramData\Anaconda3\lib\site-packages\pydotplus\graphviz.py in <lambda>(f, prog)
   1795             self.__setattr__(
   1796                 'create_' + frmt,
-> 1797                 lambda f=frmt, prog=self.prog: self.create(format=f, prog=prog)
   1798             )
   1799             f = self.__dict__['create_' + frmt]

C:\ProgramData\Anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format)
   1958             if self.progs is None:
   1959                 raise InvocationException(
-> 1960                     'GraphViz\'s executables not found')
   1961 
   1962         if prog not in self.progs:

InvocationException: GraphViz's executables not found
Stephen
  • 29
  • 6
  • 1) Do you have GraphViz installed? if you do not have it: install it and add the folder containing GraphViz executables to your (system) path. 2) If it is installed check if the executables are added to your (system) Path: if not add them. – error Jun 22 '18 at 07:12
  • Possible duplicate of [Why is pydot unable to find GraphViz's executables in Windows 8?](https://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8) – error Jun 22 '18 at 07:13
  • Thank you. GraphViz already installed. How do I check if the executables are added to my Path? – Stephen Jun 22 '18 at 15:28
  • On the duplicate, the basic answer to the other link was to add the bin file to the Path. When I went to the GraphViz folder, no such bin folder exists. – Stephen Jun 22 '18 at 16:26

0 Answers0