February 2018
Intermediate to advanced
378 pages
10h 14m
English
Let us take a look at the code to visualize a tree as follows:
In []:
labels = df.label.astype('category').cat.categories
labels = list(labels)
labels
Out[]:
[u'platyhog', u'rabbosaurus']
Define a variable to store all the names for the features:
In []:
feature_names = map(lambda x: x.encode('utf-8'), features.columns.get_values())
feature_names
Out[]:
['length',
'fluffy',
'color_light black',
'color_pink gold',
'color_purple polka-dot',
'color_space gray']
Then, create the graph object using the export_graphviz function:
In []: import pydotplus dot_data = tree.export_graphviz(tree_model, out_file=None, feature_names=feature_names, class_names=labels, filled=True, rounded=True, special_characters=True) dot_data Out[]: ...
Read now
Unlock full access