【发布时间】:2020-04-06 11:04:51
【问题描述】:
我想显示基于决策树模型输出的 Graphviz 决策树图像,因为它更具表现力,但是初始模型输出中的临界值“gini”或“熵”未显示在 graphviz树输出。
我遵循了这个教程:https://www.datacamp.com/community/tutorials/decision-tree-classification-python
用于决策树输入的代码:
clf = tree.DecisionTreeClassifier(max_leaf_nodes = 3, min_samples_leaf = 5, max_depth =4)
clf = clf.fit(X_train, y_train)
tree.plot_tree(clf.fit(X_train, y_train))
决策树模型的输出:https://i.stack.imgur.com/NprzI.png
用于graphviz输入的代码:
dot_data = StringIO()
tree.export_graphviz(clf, out_file = dot_data, feature_names = inputs.columns,class_names =['0','1'], filled = True, rounded = True, impurity = False)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
graphviz 决策树的输出:https://i.stack.imgur.com/5Q9D6.png
我在 clf 树的参数中添加了criteria = "gini"(尽管它不是必需的,因为它默认设置为 gini),但不会对 graphviz 输出进行更改。
我还在 clf 树的参数中添加了criteria = "entropy",它将输出从 gini 更改为熵,并显示在树模型输出上,但不显示在 graphviz 输出上。
我没有在文档或其他地方看到任何内容来说明为什么会出现这种情况,并且对于显示使用中的标准很有用。
我是否遗漏了某个地方的参数?
【问题讨论】:
标签: python output graphviz decision-tree pygraphviz