Explore Courses Blog Tutorials Interview Questions
0 votes
in Machine Learning by (19k points)

My code is to follow the class of machine learning of google. The two code is the same. I don't know why it shows an error. Maybe the type of variable is an error. But google's code is the same as me. Who has ever had this problem?

This is error

[0 1 2]

[0 1 2]

Traceback (most recent call last):

  File "/media/joyce/oreo/python/machine_learn/", line 34, in <module>


AttributeError: 'list' object has no attribute 'write_pdf'

[Finished in 0.4s with exit code 1]

[shell_cmd: python -u "/media/joyce/oreo/python/machine_learn/"]

[dir: /media/joyce/oreo/python/machine_learn]

[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

This is code

import numpy as np

from sklearn.datasets import load_iris

from sklearn import tree

iris = load_iris()

test_idx = [0, 50, 100]

# training data

train_target = np.delete(, test_idx)

train_data = np.delete(, test_idx, axis=0)

# testing data

test_target =[test_idx]

test_data =[test_idx]

clf = tree.DecisionTreeClassifier(), train_target)

print test_target

print clf.predict(test_data) 

# viz code

from sklearn.externals.six import StringIO

import pydot

dot_data = StringIO()





        filled=True, rounded=True,


graph = pydot.graph_from_dot_data(dot_data.getvalue())


2 Answers

0 votes
by (33.1k points)

You can simply use the PyDot library of Python to save/print a graph. It is built on top of Graphviz, which was most commonly used for printing graphs.


import  pydot


returns a list, so try:

graph = pydot.graph_from_dot_data(dot_data.getvalue())


Hope this answer helps.

0 votes
by (41.4k points)

Use the below code where pydot.graph_from_dot_data() returns a list.

graph = pydot.graph_from_dot_data(dot_data.getvalue())


Browse Categories