sklearn.tree.export_graphviz¶
- sklearn.tree.export_graphviz(decision_tree, out_file='tree.dot', feature_names=None, max_depth=None, close=None)¶
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)
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.
feature_names : list of strings, optional (default=None)
Names of each of the features.
max_depth : int, optional (default=None)
The maximum depth of the representation. If None, the tree is fully generated.
Examples
>>> 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')