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

Python 在决策树可视化过程中,位置参数跟随关键字参数错误,python,machine-learning,jupyter-notebook,graphviz,decision-tree,Python,Machine Learning,Jupyter Notebook,Graphviz,Decision Tree,我试图生成决策树的可视化。但是,我遇到了一个无法解决的错误。 这是我的代码: 从sklearn.tree导入导出\u graphviz 从sklearn.externals.six导入StringIO 从IPython.display导入图像 导入pydotplus 特征值=[“缺勤原因”、“缺勤月份”] 特色菜 dot_data=StringIO() export_graphviz(clf,out_file=dot_data,filled=True,rounded=True,special_

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

从sklearn.tree导入导出\u graphviz
从sklearn.externals.six导入StringIO
从IPython.display导入图像
导入pydotplus
特征值=[“缺勤原因”、“缺勤月份”]
特色菜
dot_data=StringIO()
export_graphviz(clf,out_file=dot_data,filled=True,rounded=True,special_characters=True,feature_name=feature_cols,class_name['0','1'])
graph=pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png('tree.png'))

Image(graph.create_png())
您缺少一个
=
,您应该将最后一个参数更新为
类名=['0','1']

export_graphviz(clf, out_file=dot_data, filled=True, rounded=True, 
    special_characters=True, 
    feature_names = feature_cols, 
    class_names=['0', '1'])

现在,我的列表索引超出了范围。@HalfMartianHalfHuman这可能与您的
y
有关,如果有两种以上的结果类型(多分类而不是二进制),您需要提供相同数量的类名称实际上,我已删除
类名称=['0',1'])
来自
功能\u名称
并生成可视化