Visualizing a decision tree with pydot
If you would like to produce graphs, install the pydot
library. Unfortunately, for Windows this installation could be non-trivial. Please focus on looking at the graphs rather than reproducing them if you struggle to install pydot
.
How to do it...
- Within an IPython Notebook, perform several imports and type the following script:
import numpy as np from sklearn import tree from sklearn.externals.six import StringIO import pydot from IPython.display import Image dot_iris = StringIO() tree.export_graphviz(dtc, out_file = dot_iris, feature_names = iris.feature_names) graph = pydot.graph_from_dot_data(dot_iris.getvalue()) Image(graph.create_png())

How it works...
This is the decision tree that was produced with the training; calling the fit
method on X_train
and y_train
. Look at it closely, starting at the top of the tree. You have 105 samples in the training set. The training set is split into three sets of 35 each: value = [35, 35, 35]. Explicitly, these...