【发布时间】:2018-07-14 21:33:34
【问题描述】:
export_graphviz 未定义错误!!
Used the following codes in Jupyrer notebook Python 3.x
`def show_tree (tree, features, path):
f = io.StringIO()
export_graphviz(tree, out_file = f, feature_names=features )
pydotplus.graph_from_dot_data(f.getvalue()).write_png(path)
img = misc.imread(path)
plt.rcParams['figure.figsize']=[20,20]
plt.imshow(img)
show_tree(dt,features,'dc_tree.png') `
调用函数show_tree时出现如下错误
`NameError Traceback (most recent call last)
<ipython-input-21-96002279767f> in <module>()
----> 1 show_tree(dt,features,'dc_tree.png')
`<ipython-input-20-f73dae020a9a> in show_tree(tree, features, path)
4 def show_tree (tree, features, path):
5 f = io.StringIO()
----> 6 export_graphviz(tree, out_file = f, feature_names=features )
7 pydotplus.graph_from_dot_data(f.getvalue()).write_png(path)
8 img = misc.imread(path)`
NameError:名称“export_graphviz”未定义
【问题讨论】:
-
错误表示当前闭包中没有函数
export_graphviz的定义