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
Use the CART pseudocode to follow recursive tree growth, split selection, and stopping structure before reading the implementation. section 5.6












