我编写了代码来可视化决策树模型。最初,我遇到了像 graphviz的可执行文件未找到这样的错误,但我添加了它的路径到enivronment变量,甚至重新安装了graphviz模块。它现在似乎工作正常。但现在出现以下错误:
Traceback (most recent call last):
File "C:/Ankur/Python36/Python Files/Decision_Tree.py", line 57, in
<module>
Image(graph.create_png())
TypeError: 'module' object is not callable
代码如下。
from sklearn import tree
from io import StringIO
from PIL import Image
from graphviz import Graph
import pydotplus as py
# Code for creating the model and fitting the data.
#...........................
dot_data=StringIO()
tree.export_graphviz(clf,out_file=dot_data)
graph=py.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
答案 0 :(得分:1)
Image
是一个模块,而不是一个函数。请参阅:from PIL import Image
您可能打算Image.open(graph.create_png())
。