[] Installing and Using machine learning decision trees graphviz package graphic visualization of the pdf file

Install graphviz
conda install -c anaconda graphviz	# -c 选择源(channel)
pip install pydot
conda install python-graphviz
Pdf file generated graphics tree
from sklearn.datasets import load_iris
from sklearn import tree
from sklearn.externals.six import StringIO  
import pydot 

clf = tree.DecisionTreeClassifier()
iris = load_iris()
clf = clf.fit(iris.data, iris.target)

dot_data = StringIO() 
tree.export_graphviz(clf, out_file=dot_data) 
graph = pydot.graph_from_dot_data(dot_data.getvalue()) 

graph[0].write_pdf("iris.pdf")  # must access graph's first element

View Files:

:ls | grep iris.pdf
iris.pdf

Last picture:
Here Insert Picture Description

Reference: https://scikit-learn.org/stable/modules/tree.html#classification

Published 275 original articles · won praise 13 · views 70000 +

Guess you like

Origin blog.csdn.net/LU_ZHAO/article/details/105168378