liveBook · Manning

Decision tree

As explained in Machine Learning Algorithms in Depth

A decision tree is a hierarchical predictive model that makes decisions by applying feature-based tests at internal nodes.

A decision tree is a hierarchical predictive model that partitions an input space into axis-parallel regions. Each leaf classifies its region by majority vote or predicts its expected value for regression. section 5.6

CART grows a binary tree by repeatedly choosing a feature and threshold that produce the lowest partition cost. For feature j, candidate thresholds are midpoints between observed values. Because optimal partitioning is NP-complete, the construction uses a greedy recursive procedure. section 5.6

Training focuses on balancing purity against generalization:

  • Represent the training data as an n-by-d matrix, then search each feature and its candidate thresholds. section 5.6
  • Evaluate each split using an impurity objective. The Gini index measures expected classification error within a leaf and becomes zero for a pure leaf. section 5.6
  • Limit tree depth while minimizing impurity to reduce underfitting and overfitting; entropy provides an alternative objective. section 5.6
  • Inspect the resulting tree for interpretability and feature-importance insight. section 5.6

From-scratch CART classifier

A Python implementation can represent each node with its Gini value, sample counts, class counts, class label, selected feature, threshold, and left and right children. A classifier object stores max_depth and searches for the best split; an Iris-data workflow then evaluates predictions with accuracy. section 5.6

Figure 5.14 CART decision tree algorithm pseudo-code
figure

Use the CART pseudocode to follow recursive tree growth, split selection, and stopping structure before reading the implementation. section 5.6

How Machine Learning Algorithms in Depth covers it

How deep it goes
Derives feature-threshold selection, impurity objectives, and recursive growth, then implements CART while deferring complete optimization details.
Examples
Demonstrates CART with an Iris dataset workflow, accuracy scoring, and a from-scratch node-and-classifier implementation.
What you can do after
Build it from scratch by selecting thresholds, minimizing impurity, growing nodes recursively, and evaluating classification predictions.
How it connects
Connects supervised learning, classification, regression, Gini index, entropy, feature importance, and overfitting.

Also explained in

Compare how 13 books explain decision tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.