Tag Archives: Decision tree

[Solved] Decision tree error: Graphviz’s executables not found

Decision tree code

from sklearn.datasets import load_iris
import pydotplus
from IPython.display import Image
from sklearn import tree
#Training Model
iris=load_iris()
clf=tree.DecisionTreeClassifier()
clf=clf.fit(iris.data,iris.target)

#Drawing
dot_data=tree.export_graphviz(decision_tree=clf,
                              out_file=None,
                              rounded=True,
                              filled=True,
                              feature_names=iris.feature_names)
graph=pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())

Installation

Install pydotplus

pip install pydotplus

Running error: graphviz’s executables not found

Installing graphviz

pip install graphviz

Graphviz’s executables not found

After consulting the data, graphviz belongs to an independent software, which needs to be downloaded and installed on the official website

Website: http://www.graphviz.org/Download

Add environment variable

There are two methods, and the second one is recommended for personal test

Method 1: add the path of graphviz’s bin directory in environment variable.

Method 2: OS method

CMD

python

Enter Python environment

imoprt os
os.environ["PATH"]+= os.pathsep+"C:/Program Files/Graphviz/bin"  # change to your path of Graphviz

Done!

Operation results

If it is used in jupyter notebook like me, you need to restart jupyter notebook

[Solved] graphviz Error: failed to execute [‘dot’, ‘-Tsvg’], make sure the Graphviz executables are on your systems’ PATH

 

graphviz error: failed to execute [‘dot’, ‘-Tsvg’], make sure the Graphviz executables are on your systems’ PATH

1. Download graphviz

Go to https://graphviz.org/download/ to download graphviz (64-bit system must choose 64-bit Installer, can not choose ZIP)

2. Installation

In the following interface, you must select the red option (if not selected, you can only manually add environment variables later), and then you can finish all the way.

3. Test

win + R, type cmd, open the cmd window, use dot -version test, can display the version information is installed successfully
(Do not blindly open CMD, if the open is C:\WINDOWS\system32> that can not be measured)

Note: if not, restart anaconda.