Python: Using pydot and Graphviz to generate PDF file for Decision Tree
from sklearn import datasets
from sklearn import tree
from sklearn .externals.six import StringIO
import pydot
clf = tree.DecisionTreeClassifier()
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.write_pdf("iris.pdf")
Remark: (OS: OS X El Capitan)
1. You must install pydot2 firstly.
Ref:
http://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8
http://stackoverflow.com/questions/27666846/pydot-invocationexception-graphvizs-executables-not-found
http://hackercodex.com/guide/python-development-environment-on-mac-osx/
http://hackercodex.com/guide/mac-osx-mavericks-10.9-configuration/
from sklearn import tree
from sklearn .externals.six import StringIO
import pydot
clf = tree.DecisionTreeClassifier()
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.write_pdf("iris.pdf")
Remark: (OS: OS X El Capitan)
1. You must install pydot2 firstly.
pip install pydot22. Then, you must install Graphviz by using "brew"
brew install graphviz3. How to install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Ref:
http://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8
http://stackoverflow.com/questions/27666846/pydot-invocationexception-graphvizs-executables-not-found
http://hackercodex.com/guide/python-development-environment-on-mac-osx/
http://hackercodex.com/guide/mac-osx-mavericks-10.9-configuration/
留言
張貼留言