7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pydotplusでgraphvizのパスが解決できない場合の対処法

Posted at

#はじめに

sklearn.tree.tree.DecisionTreeClassifier を使用すると決定木の結果を.dot形式で出力することができます。これらはpydotplusなどを使って、jupyter notebook上にインライン表示するTipsなどが公開されていますが、

InvocationException: GraphViz's executables not found

といった、Graphvizのパスが解決できないというエラーが出ることがあります。

その問題を解決するTipsを紹介します。

#コード

ポイントは、graph_from_dot_data()の戻り値に対して、dot.exeへのパスをdictionaryで渡す点です。


import io
import pydotplus as pdot
from sklearn.tree import export_graphviz
from IPython.display import Image

dot_data = io.StringIO()
export_graphviz(tree,out_file=dot_data,feature_names=iris.feature_names)

graph = pdot.graph_from_dot_data(dot_data.getvalue())

#dot.exeへのパスをdictで渡す
graph.progs = {'dot': u"C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe"}

Image(graph.create_png())

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?