1

using pycharm, python3.7 with windows 10.

the problematic part of my code is -

import pandas as pd
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import pydotplus  # GraphVis for tree
from sklearn import tree
...
clf = tree.DecisionTreeClassifier()
clf.fit(X_train,y_train)
print("Decision Tree Precision:" + str(clf.score(X_test,y_test)))
dot_data = tree.export_graphviz(clf, out_file=None,
                    feature_names=no_labels.columns, # all columns
                                # without result.
                     class_names=["1","2","3"], # all unique results
                     filled=True, rounded=True,
                     special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_png('wineTree.png')  # <- problem!
fig, ax = plt.subplots(figsize=(24, 24))
ax.imshow(plt.imread('wineTree.png')) #name
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.show()

i get an error -

Traceback (most recent call last):
  File "C:/Users/ASUS/PycharmProjects/DataProject/clustering/clustering.py", line 66, in <module>
    vis_tree(clf)
  File "C:/Users/ASUS/PycharmProjects/DataProject/clustering/clustering.py", line 35, in vis_tree
    graph.write_png('wineTree.png') #name
  File "C:\Users\ASUS\PycharmProjects\DataProject\venv\lib\site-packages\pydotplus\graphviz.py", line 1810, in <lambda>
    prog=self.prog: self.write(path, format=f, prog=prog)
  File "C:\Users\ASUS\PycharmProjects\DataProject\venv\lib\site-packages\pydotplus\graphviz.py", line 1918, in write
    fobj.write(self.create(prog, format))
  File "C:\Users\ASUS\PycharmProjects\DataProject\venv\lib\site-packages\pydotplus\graphviz.py", line 1960, in create
    'GraphViz\'s executables not found')
pydotplus.graphviz.InvocationException: GraphViz's executables not found

although I imported graphviz 0.14.1 and pydotplus 2.0.2 (latest versions) note - do not user jupyter, tried downloading from https://graphviz.org/download/ -> Stable Windows install packages, got to non existing page. should i download something else?

Thank you!

btw - saw this pydotplus.graphviz.InvocationException: GraphViz's executables not found and - GraphViz's executables not found - Why are there no executables installed after installation of graphViz via pip?

  • For the Windows executables, I used [this installer](https://www2.graphviz.org/Packages/stable/windows/10/cmake/Release/x64/). I followed the instructions [here](https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224), paying particular attention to the steps involving the correct execution of `dot -c` and the need to ensure the `config6` is created. After that, try `pydotplus` again. – andrewJames Sep 26 '20 at 14:10
  • thank you so much! i installed it, for some reason when i type dot -c i get "dot is not recognized as an internal or external command, operable program or batch file." – learningtocode Sep 27 '20 at 22:32
  • Make sure the `dot.exe` directory is on your path (see step 10 in the detailed instructions I linked to). For me, I needed this PATH entry: `C:\Program Files\Graphviz 2.44.1\bin`. Yours may be different... And make sure you open a new console **after** making that change, to pick up the PATH changes. – andrewJames Sep 27 '20 at 22:47

0 Answers0