Python is pretty new to me.
I am trying to run an example of machine learning titanic in the book "Machine Science in Python with Scikit". Classification with decision trees works fine (clf is defined correctly), but if I want to visualize the decision tree (see the code snippet below), I received the following error message (copied from IPython).
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-34-15b1b4a5d909> in <module>() 3 dot_data = StringIO.StringIO() 4 tree.export_graphviz(clf, out_file = dot_data, feature_names = ['PClass', 'AgeFill', 'Gender']) ----> 5 graph = pydot.graph_from_dot_data(dot_data.getvalue()) 6 graph.write_png('titanic.png') C:\Users\885299\AppData\Local\Continuum\Anaconda32\lib\site-packages\pydot.pyc in graph_from_dot_data(data) 218 """ 219 --> 220 return dot_parser.parse_dot_data(data) 221 222 NameError: global name 'dot_parser' is not defined
Can someone help me?
A snippet of code that I used (similar to a book):
import pydot, StringIO dot_data = StringIO.StringIO() tree.export_graphviz(clf, out_file = dot_data, feature_names = ['Class', 'Age', 'Gender']) graph = pydot.graph_from_dot_data(dot_data.getvalue()) graph.write_png('titanic.png') from IPython.core.display import Image Image(filename = 'titanic.png')
source share