1

i'm using scikitlearn to introduce me to Machine Learning, i' m following this tutorial link to yt but if i try to export the pdf decision tree i have this error: i try to do: open -w review iris.pdf and the result is :

Impossibile ottenere un descrittore di file che si riferisce alla console

if i compile from the terminal i have the error:

Traceback (most recent call last)  File "fstraining.py", line 2, in <module>
import graphviz ImportError: No module named graphviz

Thanks for the attention

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • 5
    The error is stating that you are missing a required module, did you try installing `graphviz`? – EdChum Feb 21 '18 at 11:41
  • thank you for the answer, but i have install anaconda, and now it ask me some module, how can i check if it see i'm using anaconda for that module? @EdChum –  Feb 21 '18 at 17:51
  • At the anaconda prompt enter `conda install graphviz` – EdChum Feb 21 '18 at 19:56

1 Answers1

2

Once you have built your decision tree clf, simply:

from sklearn.externals.six import StringIO   
from sklearn.tree import export_graphviz
import pydotplus

# Export resulting tree to DOT source code string
dot_data = export_graphviz(clf,
                           feature_names=col_names,
                           out_file=None,
                           filled=True,
                           rounded=True)

#Export to pdf
pydot_graph = pydotplus.graph_from_dot_data(dot_data)
pydot_graph.write_pdf('tree.pdf')

This answer is adapted from here:

Liam
  • 116
  • 1
  • 1
  • 8