Classical machine learningML 06

Decision Trees

A decision tree asks a series of yes/no questions about the features (“is fasting glucose at most 6.1 mmol/L?”), each chosen to separate the classes as cleanly as possible, until it reaches a leaf that gives a prediction. The result reads like a flowchart, which is a large part of trees’ appeal wherever a decision has to be explained, from loan approvals to clinical guidelines: anyone can follow the reasoning. Hover over the plot to see the path a patient there would take, or over a node to see its region. The data are fictional and simplified.

feature spacelive
click: add point · right-click: remove · hover: see its path

The tree left branch = yes · bar = mix of classes in the node · hover a node to see its region

shading: the class predicted in each region, stronger where the leaf is purer · lines: splits, thicker nearer the root · hollow: test points

How a split is chosen

At each node the tree tries every possible threshold on every feature and keeps the one that makes the two groups purest. Purity is measured by Gini impurity (the chance that two points drawn at random from the node belong to different classes) or by entropy; both are zero when a node holds only one class. The search is greedy, one question at a time, and every question compares a single feature with a threshold, so the regions are always rectangles. That is why the diagonal example needs a staircase of many splits to follow a boundary that one sloped line would describe.

Depth and overfitting

A deep enough tree can put every training point in a leaf of its own and score 100% on the training data, while carving out small boxes around noise that do not hold for new patients. Limiting the depth or the size of a leaf, or pruning the tree back afterwards, keeps it general. The electrolytes example shows this best: its normal range is round and its classes overlap at the edge, so the tree keeps splitting all the way to depth 8. Hold out a test set and raise the depth step by step: training accuracy climbs towards 100% while test accuracy peaks at a moderate depth and then falls. Random forests, which average many trees grown on resampled data, are a common way to keep the accuracy while losing some of the noise.

References

  1. Breiman, L., Friedman, J. H., Olshen, R. A., & Stone, C. J. (1984). Classification and Regression Trees. Belmont, CA: Wadsworth.
  2. Quinlan, J. R. (1986). Induction of decision trees. Machine Learning, 1(1), 81–106. doi.org/10.1007/BF00116251
  3. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.), chapter 9.2. Springer. doi.org/10.1007/978-0-387-84858-7