我正在积极学习如何在Python中实现决策树。
重新创建来自scikit-learn的Iris分类示例时,我会得到一个TypeError错误,错误涉及export_graphviz中存在的'class_names'和'plot_options'参数。
from IPython.display import Image
import sklearn
dot_data = StringIO()
sklearn.tree.export_graphviz(clf, out_file=dot_data,
plot_options=['class', 'filled', 'label', 'sample', 'proportion'],
target_names=iris['target_names'],
feature_names=iris['feature_names'])
graph = pydot.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
以上代码的错误为:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-aba117838252> in <module>()
5 plot_options=['class', 'filled', 'label', 'sample', 'proportion'],
6 target_names=iris['target_names'],
----> 7 feature_names=iris['feature_names'])
8 graph = pydot.graph_from_dot_data(dot_data.getvalue())
9 Image(graph.create_png())
TypeError: export_graphviz() got an unexpected keyword argument 'plot_options'
在我的电脑上,我已经安装了graphviz和pydot2。当我尝试安装pygraphviz时,出现了一个错误:
If you think your installation is correct you will need to manually
change the include_dirs and library_dirs variables in setup.py to
point to the correct locations of your graphviz installation.
The current setting of library_dirs and include_dirs is:
library_dirs=None
include_dirs=None
error: Error locating graphviz.
有没有办法可以让我使用export_graphviz参数来构建我想要的树形可视化呢?是否解决pygraphviz安装错误能够解决我的问题呢?
谢谢。
plot_options
、target_names
等等?你想要精确地可视化什么? - Ibraim Ganiev