Building the decision tree

As shown earlier, we can create a decision tree using scikit-learn's tree module. For now, let's not specify any optional arguments:

  1. We will start off by creating a decision tree:
In [5]: from sklearn import tree...     dtc = tree.DecisionTreeClassifier()
  1. Do you remember how to train the decision tree? We will use the fit function for that:
In [6]: dtc.fit(X_train, y_train)Out[6]: DecisionTreeClassifier(class_weight=None, criterion='gini',                               max_depth=None, max_features=None,                               max_leaf_nodes=None,                               min_impurity_split=1e-07,                               min_samples_leaf=1,                               min_samples_split=2,                               min_weight_fraction_leaf=0.0,                               presort=False, random_state=None,                               splitter='best')
  1. Since we did not specify any pre-pruning parameters, we would expect this ...

Get Machine Learning for OpenCV 4 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.