sklearn.tree.export_graphviz(decision_tree, out_file=”tree.dot”, max_depth=None, feature_names=None, class_names=None, label=’all’, filled=False, leaves_parallel=False, impurity=True, node_ids=False, proportion=False, rotate=False, rounded=False, special_characters=False, precision=3)
[source]
Export a decision tree in DOT format.
This function generates a GraphViz representation of the decision tree, which is then written into out_file
. Once exported, graphical renderings can be generated using, for example:
$ dot -Tps tree.dot -o tree.ps (PostScript format) $ dot -Tpng tree.dot -o tree.png (PNG format)
The sample counts that are shown are weighted with any sample_weights that might be present.
Read more in the User Guide.
Parameters: |
decision_tree : decision tree classifier The decision tree to be exported to GraphViz. out_file : file object or string, optional (default=’tree.dot’) Handle or name of the output file. If max_depth : int, optional (default=None) The maximum depth of the representation. If None, the tree is fully generated. feature_names : list of strings, optional (default=None) Names of each of the features. class_names : list of strings, bool or None, optional (default=None) Names of each of the target classes in ascending numerical order. Only relevant for classification and not supported for multi-output. If label : {‘all’, ‘root’, ‘none’}, optional (default=’all’) Whether to show informative labels for impurity, etc. Options include ‘all’ to show at every node, ‘root’ to show only at the top root node, or ‘none’ to not show at any node. filled : bool, optional (default=False) When set to leaves_parallel : bool, optional (default=False) When set to impurity : bool, optional (default=True) When set to node_ids : bool, optional (default=False) When set to proportion : bool, optional (default=False) When set to rotate : bool, optional (default=False) When set to rounded : bool, optional (default=False) When set to special_characters : bool, optional (default=False) When set to precision : int, optional (default=3) Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node. |
---|---|
Returns: |
dot_data : string String representation of the input tree in GraphViz dot format. Only returned if New in version 0.18. |
>>> from sklearn.datasets import load_iris >>> from sklearn import tree
>>> clf = tree.DecisionTreeClassifier() >>> iris = load_iris()
>>> clf = clf.fit(iris.data, iris.target) >>> tree.export_graphviz(clf, ... out_file='tree.dot')
© 2007–2017 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html