Chapter 7

Decision trees

A tree recursively partitions the input space. At each node, a greedy algorithm compares candidate splits using weighted child impurity. A locally best split need not produce the globally best tree.

7.1 Classification impurity and split gain

Past papers · DA 2024–2026 (3 papers): 1 question, 2 marks

At a node containing NN observations, let pc=Nc/Np_c=N_c/N be the fraction belonging to class cc, with CC classes. Define 0log⁡20=00\log_2 0=0 by continuity.

A pure node has zero impurity. For uniform class proportions, entropy is log⁡2C\log_2 C, Gini is 1−1/C1-1/C, and majority error is 1−1/C1-1/C. Binary maxima are 1,1/2,1/21,1/2,1/2. The Gini value is also the probability of unequal labels in two independent draws from the node distribution.

For a numerical feature, sort its distinct training values and test thresholds between adjacent values. A split xj≤tx_j\le t must use a consistent equality convention. Repeated feature values cannot be separated by a threshold. Leaves predict a most frequent class; their empirical class probabilities are class counts divided by leaf count.

7.2 Regression leaves and pruning

For a regression node AA, targets are numerical. Under squared error, the prediction is their mean yˉA\bar y_A. For absolute error, use a median. These predictions make a tree piecewise constant.

Choose the split with greatest SSE decrease. Dividing every candidate's total SSE by the same parent count preserves the ranking. Limit depth, enforce a minimum leaf size, or prune to control overfitting; tune those choices on validation data. Axis-aligned trees need repeated rectangular splits to approximate a diagonal boundary. Increasing tree depth normally reduces training error but can increase variance.

Last-minute recall

  • Node proportions refer to that node, not the whole dataset.
  • Entropy is zero at purity and largest at uniform class proportions.
  • Child impurity is sample-weighted.
  • Numerical thresholds are tested between distinct feature values.
  • Squared-error regression leaves predict means.
  • Pruning trades fit against the number of leaves.

Revise offline: the whole Machine Learning handbook as one PDF

42 pages · 1.8 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections