In [9]:
from sklearn.tree import DecisionTreeRegressor
from bokeh.sampledata.autompg import autompg

In [10]:
d=DecisionTreeRegressor()

In [11]:
autompg.info()
autompg.columns


<class 'pandas.core.frame.DataFrame'>
Int64Index: 392 entries, 0 to 391
Data columns (total 9 columns):
mpg       392 non-null float64
cyl       392 non-null int64
displ     392 non-null float64
hp        392 non-null int64
weight    392 non-null int64
accel     392 non-null float64
yr        392 non-null int64
origin    392 non-null int64
name      392 non-null object
dtypes: float64(3), int64(5), object(1)
memory usage: 30.6+ KB
Out[11]:
Index([u'mpg', u'cyl', u'displ', u'hp', u'weight', u'accel', u'yr', u'origin',
       u'name'],
      dtype='object')

In [13]:
y=autompg.pop('mpg')
x=autompg[[u'cyl', u'displ', u'hp', u'weight', u'accel', u'yr', u'origin']]

In [15]:
d.fit(x,y)


Out[15]:
DecisionTreeRegressor(criterion='mse', max_depth=None, max_features=None,
           max_leaf_nodes=None, min_samples_leaf=1, min_samples_split=2,
           min_weight_fraction_leaf=0.0, random_state=None,
           splitter='best')

In [24]:
from IPython.display import Image 
from sklearn.externals.six import StringIO 
dot_data = StringIO() 
tree.export_graphviz(d, out_file=dot_data,  
                         feature_names=iris.feature_names,  
                         class_names=iris.target_names,  
                         filled=True, rounded=True,  
                         special_characters=True)  
graph = pydot.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-24-ea448ec5f764> in <module>()
      2 from sklearn.externals.six import StringIO
      3 dot_data = StringIO()
----> 4 tree.export_graphviz(d, out_file=dot_data,  
      5                          feature_names=iris.feature_names,
      6                          class_names=iris.target_names,

NameError: name 'tree' is not defined