[]インストールと機械学習決定木を使用すると、PDFファイルのグラフィック表示をパッケージ化graphvizの

graphvizのインストール
conda install -c anaconda graphviz	# -c 选择源(channel)
pip install pydot
conda install python-graphviz
PDFファイル生成されたグラフィックスツリー
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

ビューのファイル:

:ls | grep iris.pdf
iris.pdf

最後の写真:
ここに画像を挿入説明

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

公開された275元の記事 ウォン称賛13 ビュー70000 +

おすすめ

転載: blog.csdn.net/LU_ZHAO/article/details/105168378