我想显示一个基于决策树模型输出的Graphviz决策树图像,因为它更形象,但是,来自初始模型输出的临界值“基尼”或“熵”没有显示在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更改为entropy,并显示在树模型输出上,但不显示在graphviz输出上
我没有在文档或其他地方看到任何东西来说明为什么会出现这种情况,并将有助于显示正在使用的标准
我是不是漏掉了一个参数
从
sklearn.tree.export_graphviz
的文档中:然后显式地将其设置为
False
:如果将其设置为
False
,它将不会出现在绘图中相关问题 更多 >
编程相关推荐