Decision Trees

The mathematical framework of recursive partitioning: impurity measures (Gini, entropy, MSE), optimal split criteria, the greedy induction algorithm, pruning theory, and computational complexity analysis.

Intermediate

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. Recursive Partitioning Framework
  5. Impurity Measures
  6. Information Gain and Split Criteria
  7. The Greedy Induction Algorithm
  8. Regression Trees
  9. Pruning and Complexity Control
  10. Theoretical Properties
  11. Common Pitfalls
  12. Summary
  13. Exercises

Learning Objectives

  1. Formalize a decision tree as a recursive partition of input space.
  2. Derive Gini impurity and entropy as measures of node heterogeneity.
  3. Derive the information gain criterion for optimal split selection.
  4. Analyze the greedy algorithm's computational complexity.
  5. Explain cost-complexity pruning and its connection to regularized risk.
  6. Understand why trees are high-variance, low-bias estimators.

Notation

  • Rm\mathcal{R}_m — region corresponding to leaf node mm
  • NmN_m — number of training samples in region mm
  • p^mk\hat{p}_{mk} — proportion of class kk in node mm
  • H(m)H(m) — impurity of node mm
  • GG — information gain from a split
  • T|\mathcal{T}| — number of leaf nodes (tree complexity)

Core Intuition

A decision tree partitions the input space XRd\mathcal{X} \subseteq \mathbb{R}^d into axis-aligned rectangular regions, each assigned a constant prediction. The partition is built top-down: at each step, we find the split (feature jj, threshold tt) that most reduces prediction error. The resulting model is interpretable, non-parametric, and handles mixed feature types naturally.

Decision Tree Splits

58% acc
0x
x split
0.45
y split
0.55
Pred 0Pred 1x ≤ split
Explore: Decision trees partition feature space with axis-aligned splits. Each rectangle gets a class label — adjust splits to maximize accuracy.

Recursive Partitioning Framework

A tree TT defines a partition {R1,,RM}\{\mathcal{R}_1, \ldots, \mathcal{R}_M\} of X\mathcal{X} with predictions:

f(x;T)=m=1Mcm1[xRm].(1)f(\mathbf{x}; T) = \sum_{m=1}^M c_m \cdot \mathbf{1}[\mathbf{x} \in \mathcal{R}_m]. \tag{1}

For classification: cm=argmaxkp^mkc_m = \arg\max_k \hat{p}_{mk} (majority vote). For regression: cm=1NmxiRmyic_m = \frac{1}{N_m}\sum_{x_i \in \mathcal{R}_m} y_i (mean).

Each internal node implements a split xjtx_j \leq t, creating two child nodes.


Impurity Measures

Definition (Gini Impurity). For a node mm with KK classes:

HGini(m)=k=1Kp^mk(1p^mk)=1k=1Kp^mk2.(2)H_{\text{Gini}}(m) = \sum_{k=1}^K \hat{p}_{mk}(1 - \hat{p}_{mk}) = 1 - \sum_{k=1}^K \hat{p}_{mk}^2. \tag{2}

Gini impurity equals the probability that a randomly chosen sample would be misclassified if labeled according to the distribution in the node.

Definition (Entropy).

Hentropy(m)=k=1Kp^mklog2p^mk.(3)H_{\text{entropy}}(m) = -\sum_{k=1}^K \hat{p}_{mk}\log_2\hat{p}_{mk}. \tag{3}

Both are maximized when classes are uniformly distributed and minimized (zero) when the node is pure (single class).

Definition (MSE for regression).

HMSE(m)=1NmxiRm(yiyˉm)2.(4)H_{\text{MSE}}(m) = \frac{1}{N_m}\sum_{x_i \in \mathcal{R}_m}(y_i - \bar{y}_m)^2. \tag{4}

Information Gain and Split Criteria

A split ss of node mm into children mLm_L and mRm_R produces information gain:

G(m,s)=H(m)NmLNmH(mL)NmRNmH(mR).(5)G(m, s) = H(m) - \frac{N_{m_L}}{N_m}H(m_L) - \frac{N_{m_R}}{N_m}H(m_R). \tag{5}

The optimal split maximizes GG:

s=argmaxj,tG(m,(j,t)).(6)s^* = \arg\max_{j, t} G(m, (j, t)). \tag{6}

For each feature jj with VV distinct values, there are at most V1V - 1 candidate thresholds. Total candidates per node: j(Vj1)nd\sum_j (V_j - 1) \leq nd in the worst case.


The Greedy Induction Algorithm

CART Algorithm (Breiman et al., 1984):

  1. Start with root containing all nn samples.
  2. For current node mm:
    • If stopping criterion met (pure node, max depth, min samples): make leaf.
    • Otherwise: find best split s=(j,t)s^* = (j^*, t^*) maximizing gain.
    • Partition data: mL={i:xijt}m_L = \{i : x_{ij^*} \leq t^*\}, mR={i:xij>t}m_R = \{i : x_{ij^*} > t^*\}.
  3. Recurse on mLm_L and mRm_R.

Complexity. At each node with NmN_m samples: testing all splits costs O(dNmlogNm)O(d \cdot N_m\log N_m) (sort each feature). Over all nodes at a given depth: O(dnlogn)O(dn\log n). For depth DD: total O(Ddnlogn)O(Ddn\log n).


Regression Trees

For squared-error loss, the optimal constant prediction in region Rm\mathcal{R}_m is the sample mean yˉm\bar{y}_m. The best split minimizes:

imL(yiyˉmL)2+imR(yiyˉmR)2.(7)\sum_{i \in m_L}(y_i - \bar{y}_{m_L})^2 + \sum_{i \in m_R}(y_i - \bar{y}_{m_R})^2. \tag{7}

This is equivalent to maximizing the reduction in total variance — the regression analog of information gain.


Pruning and Complexity Control

An unpruned tree typically overfits (R^n=0\hat{R}_n = 0 if grown to full depth). Cost-complexity pruning regularizes:

Rα(T)=R^n(T)+αT,(8)R_\alpha(T) = \hat{R}_n(T) + \alpha|\mathcal{T}|, \tag{8}

where T|\mathcal{T}| is the number of leaves and α0\alpha \geq 0 is a complexity parameter.

Theorem (Breiman). For any α\alpha, there exists a unique smallest subtree TαTmaxT_\alpha \subseteq T_{\max} that minimizes RαR_\alpha. The sequence of optimal subtrees is nested: Tα1Tα2T_{\alpha_1} \supseteq T_{\alpha_2} for α1<α2\alpha_1 < \alpha_2.

The optimal α\alpha is selected via cross-validation.


Theoretical Properties

Consistency. Under mild conditions, decision trees are universally consistent: as nn \to \infty with appropriate depth growth (DD \to \infty, D/n0D/n \to 0), the risk converges to the Bayes risk.

Bias-Variance. Deep trees have low bias (can approximate any function on the training set) but high variance (small data perturbations change the tree structure drastically). This motivates ensemble methods (bagging, boosting) that reduce variance.

Approximation. A tree with MM leaves is a piecewise-constant function. Approximating a Lipschitz function to accuracy ϵ\epsilon in dd dimensions requires M=O(ϵd)M = O(\epsilon^{-d}) leaves — the curse of dimensionality.


Common Pitfalls

Pitfall 1. Splits are axis-aligned. If the true boundary is diagonal (e.g., x1+x2=0x_1 + x_2 = 0), trees need many splits to approximate it (staircase pattern).

Pitfall 2. Greedy splitting is not globally optimal. The best split at the root may not lead to the best overall tree. Finding the optimal tree is NP-complete.

Pitfall 3. Information gain is biased toward features with many distinct values. Gain ratio (Quinlan, C4.5) corrects this by normalizing by split entropy.


Summary

  • Decision trees recursively partition space via axis-aligned splits.
  • Gini impurity and entropy measure node heterogeneity; splits maximize information gain.
  • Trees are greedy, non-parametric, and interpretable.
  • Unpruned trees overfit; cost-complexity pruning balances fit vs. complexity.
  • High variance makes trees ideal base learners for ensembles.

Exercises

Exercise 1. Show that Gini impurity is a second-order Taylor approximation of entropy around uniform p^mk=1/K\hat{p}_{mk} = 1/K.

Exercise 2. For binary classification, show that both Gini and entropy are concave functions of pp and derive their maxima.

Exercise 3. Prove that the optimal constant prediction minimizing MSE within a region is the sample mean.

Exercise 4. Construct a 2D example where the optimal tree of depth 2 is not obtained by the greedy algorithm.

Exercise 5. Derive the number of possible binary trees with MM leaves and relate it to the Catalan numbers.