denis2887
denis2887

Reputation: 1

GraphViz's executables not found (python 3 and pydotplus)

I'm trying to learn ML, and I am a noob. Currently, I'm trying this video (https://www.youtube.com/watch?v=tNa99PG8hR8).

And my code is:

import pydotplus
import numpy as np
from sklearn.datasets import load_iris
from sklearn import tree
from sklearn.externals.six import StringIO

iris = load_iris()

##print(iris.feature_names)
##print(iris.target_names)
##print(iris.data[0])
##print(iris.target[0])

##for i in range(len(iris.target)):
##    print("Example %d: label %s, features %s" % (i, iris.target[i], iris.data[i]))

test_idx = [0,50,100]

##training data
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis=0)

##testing data
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]

clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target)

print(test_target)
print(clf.predict(test_data))

dot_data = StringIO()
tree.export_graphviz(clf,
                     out_file=dot_data,
                     feature_names=iris.feature_names,
                     class_names=iris.target_names,
                     filled=True, rounded=True,
                     impurity=False)

graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf("iris.pdf")

But the error shows:

Traceback (most recent call last):
File "C:\Users\Denis\Desktop\Machine Learning\iris.py", line 42, in graph.write_pdf("iris.pdf")
File "C:\Users\Denis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydotplus\graphviz.py", line 1810, in prog=self.prog: self.write(path, format=f, prog=prog)
File "C:\Users\Denis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydotplus\graphviz.py", line 1918, in write fobj.write(self.create(prog, format))
File "C:\Users\Denis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydotplus\graphviz.py", line 1960, in create 'GraphViz\'s executables not found') pydotplus.graphviz.InvocationException: GraphViz's executables not found

I've tried reinstall pydotplus and graphviz, but to no avail. I have no clue on how to change path. I've searched my graphviz folder, and I found no bin files.

Here's my graphviz folder and path

Upvotes: 0

Views: 5569

Answers (2)

Marcus Richard
Marcus Richard

Reputation: 43

For all those who are facing this issue in windows 10 even after trying the above mentioned steps (i.e. installing Graphviz software seperately) , this worked for me - For Windows 10 users trying to debug this same error, launch CMD as administrator (important!) and run dot -c and then run dot -v This fixed the issue for me

Upvotes: 0

Dilshat
Dilshat

Reputation: 1168

So, you installed the graphviz library for python, but you haven't installed Graphviz software I guess.
You can install it from here and make sure that the directory containing the dot executable is on your systems’ path.
Good luck in ML journey! :-)

Upvotes: 1

Related Questions