在决策树可视化过程中位置参数跟随关键字参数错误

问题描述 投票:0回答:1

我正在尝试生成决策树的可视化。但是,我遇到了无法解决的错误。这是我的代码:

from sklearn.tree import export_graphviz
from sklearn.externals.six import StringIO
from IPython.display import Image
import pydotplus

feature_cols = ['Reason_for_absence', 'Month_of_absence']
feature_cols
dot_data = StringIO()
export_graphviz(clf, out_file=dot_data, filled=True, rounded=True, special_characters=True, feature_names = feature_cols,class_names['0', '1'])
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png('tree.png')
Image(graph.create_png())

我收到以下错误:

File "", line 9
    export_graphviz(clf, out_file=dot_data, filled=True, rounded=True, special_characters=True, feature_names = feature_cols,class_names['0', '1'])
                                                                                                                            ^
SyntaxError: positional argument follows keyword argument
python machine-learning jupyter-notebook graphviz decision-tree
1个回答
0
投票

您缺少=,应该将最后一个参数更新为class_names=['0', '1']

export_graphviz(clf, out_file=dot_data, filled=True, rounded=True, 
    special_characters=True, 
    feature_names = feature_cols, 
    class_names=['0', '1'])
© www.soinside.com 2019 - 2024. All rights reserved.