当从scikit-learn重新创建Iris分类示例时,我得到了export_graphviz中存在的参数的TypeError,即’class_names’和’plot_options’.
from IPython.display import Image import sklearndot_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',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=Noneinclude_dirs=Noneerror: Error locating graphviz.
是否有解决方案允许我使用export_graphviz中的参数来构建我想要的树形象化?
寻求pygraphviz安装错误的解决方案导致我的树的解决方案?
谢谢,
解决方法 export_graphviz的签名是def export_graphviz(decision_tree,out_file="tree.dot",max_depth=None,feature_names=None,class_names=None,label='all',filled=False,leaves_parallel=False,impurity=True,node_IDs=False,proportion=False,rotate=False,rounded=False,special_characters=False):
正确的函数调用是(假设您的数据在iris对象中)
sklearn.tree.export_graphviz(clf,feature_names=iris['feature_names'],class_names=iris['target_names'],filled=True,rounded=True,special_characters=True)
如果它抛出错误
TypeError:export_graphviz()得到一个意外的关键字参数’class_names’
这意味着你的sklearn是旧版本.如果您使用的是anaconda python发行版,则可以使用更新到最新版本的sklearn
conda更新scikit-learn.如果您在任何其他发行版上,请使用pip命令.确保您的sklearn是0.17版本.
import sklearnprint sklearn.__version__总结
以上是内存溢出为你收集整理的Python – export_graphviz class_name类型错误全部内容,希望文章能够帮你解决Python – export_graphviz class_name类型错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)