Reputation: 3
I would like to display a Graphviz decision tree image based on the decision tree model output as it is more presentable however, the crition value 'gini' or 'entropy' from the initial model output, is not being displayed on the graphviz tree output.
I followed this tutorial: https://www.datacamp.com/community/tutorials/decision-tree-classification-python
Code used for decision tree input:
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))
Output of the decision tree model: https://i.sstatic.net/NprzI.png
Code used for graphviz input:
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())
Output of the graphviz decision tree: https://i.sstatic.net/5Q9D6.png
I have added criterion = "gini" within the parameters of the clf tree (although it isn't required as it is set to gini by default), but does not make a change on the graphviz output.
I have also added criterion = "entropy" within the parameters of the clf tree which changes the output from gini to entropy, and displays on the tree model output but not on the graphviz output.
I haven't seen anything in the documentation or elsewhere to suggest why this is the case and would be useful to show the criterion in use.
Am I missing out a parameter somewhere?
Upvotes: 0
Views: 1012
Reputation: 36704
From the documentation of sklearn.tree.export_graphviz
:
Parameters:
impurity: bool, optional (default=True)
And you set it explicitly to False
there:
tree.export_graphviz(... impurity = False)
If you set it to False
it won't appear in the plot.
Upvotes: 0