带有pydotplus的图决策树

时间:2018-06-21 20:55:16

标签: python pandas graphviz decision-tree pydot

am试图创建scikit-learn决策树模型的图形版本。我的目标是对其进行可视化,并最终将其另存为.png文件(.jpeg也可以工作)。基于这个网站-https://medium.com/@rnbrown/creating-and-visualizing-decision-trees-with-python-f8e8fa394176-,我使用pydot编写了以下代码。它给出了以下错误,我想知道是否有人知道如何解决这个问题。

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

0 个答案:

没有答案