Graphviz 使用Pydot创建图形时出现属性错误
我正在Windows10上使用IPython进行训练并绘制决策树。我知道下面的代码很久以前在linux上工作过。我安装了pydot,还安装了graphviz(正确指定了路径) 我得到以下错误:Graphviz 使用Pydot创建图形时出现属性错误,graphviz,pydot,Graphviz,Pydot,我正在Windows10上使用IPython进行训练并绘制决策树。我知道下面的代码很久以前在linux上工作过。我安装了pydot,还安装了graphviz(正确指定了路径) 我得到以下错误: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) &
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-3452aa5e9794> in <module>()
15 tree.export_graphviz(tree_clf, out_file=dot_data)
16 graph = pydot.graph_from_dot_data(dot_data.getvalue())
---> 17 display.Image(graph.create_png())
AttributeError: 'list' object has no attribute 'create_png'
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在()
15 tree.export_graphviz(tree_clf,out_file=dot_数据)
16 graph=pydot.graph_from_dot_data(dot_data.getvalue())
--->17 display.Image(graph.create_png())
AttributeError:“list”对象没有属性“create\u png”
我通过将所有的pydot
命令更改为pydotplus
(包括import pydotplus
)解决了这个问题。可能可以使用!pip安装pydotplus
以安装pydotplus包
参考文献
请格式化输出,使其可读性我已删除未格式化文本-它只是dot_data.getvalue()中包含的值,此时可能不相关是的,在python 3.5中,这是解决问题的唯一方法。谢谢
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-3452aa5e9794> in <module>()
15 tree.export_graphviz(tree_clf, out_file=dot_data)
16 graph = pydot.graph_from_dot_data(dot_data.getvalue())
---> 17 display.Image(graph.create_png())
AttributeError: 'list' object has no attribute 'create_png'