"class_names" export_graphviz意外的关键字错误



使用以下代码:

classes = ['ham', 'spam']
dot_data = StringIO()
with open("./plots/ritesh.dot", "w") as f:
    export_graphviz(dt_old.named_steps['classifier'], out_file=f, feature_names=vocab1, class_names=classes)

我得到错误作为意外的关键字参数。

Traceback (most recent call last):
  File "DecisionTree.py", line 198, in <module>
    main()
  File "DecisionTree.py", line 133, in main
    export_graphviz(dt_old.named_steps['classifier'], out_file=f, feature_names=vocab1, class_names=classes)
TypeError: export_graphviz() got an unexpected keyword argument 'class_names'

但在scikit学习文档中明确提到

sklearn.tree.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)

TypeError的原因是什么?

您安装的sklearn版本可能与文档一起过期。如果您使用anaconda安装了sklearn,请在命令行中尝试"conda update scikit learn"

相关内容

  • 没有找到相关文章

最新更新