liveBook · Manning

Leaf node

As explained in Grokking Machine Learning, Second Edition

A terminal tree node that is not split further and stores the output prediction for its associated samples.

A leaf node, or leaf, is the stopping point of a decision tree: it has no outgoing branches. After a sequence of yes-or-no questions, arriving at a leaf gives the tree’s decision. A decision stump has one root question and two leaves. section 9.0 section 9.0

Choosing a jacket

Ask, “Is it raining?” A yes branch can end at a leaf meaning “wear a jacket,” while a no branch can end at a leaf meaning “do not wear a jacket.” No more question is asked once either leaf is reached. section 9.0

During training, a node begins as a possible leaf associated with a group of samples. If splitting it is useful and permitted, it becomes a decision node and produces two new leaves. If it cannot be improved further, or a stopping condition prevents another split, it remains a leaf and receives the most common label among its samples as its prediction. section 9.6 section 9.5

A pure group of samples naturally becomes a leaf: all its labels match, so there is no classification improvement left to gain by splitting. A group with mixed labels may be split again, producing new leaves for its resulting groups. section 9.4

Leaf nodes matter because they determine both predictions and tree complexity:

  • At prediction time, traverse from the root through the branch selected at each decision node; the reached leaf supplies its associated label. section 9.6
  • Very small leaves can overfit, so a minimum leaf size can reject splits that would leave too few samples. section 9.5
  • A maximum depth or impurity threshold can also stop splitting and leave a node terminal. section 9.5
  • In a classifier, a mixed leaf predicts its majority label; a tie can require a default choice. section 9.13
Figure 9.2 A regular decision tree with a root node, decision nodes, branches, and leaves. Note that each decision node contains a yes-or-no question. From each possible answer, one branch emanates, which can lead to another decision node or a leaf. This tree has a depth of 2, because the longest path from a leaf to the root goes through two branches.

Use the diagram to trace how branches connect a root and decision nodes to terminal leaves, and to see how leaf distance contributes to tree depth. section 9.0

App recommendation leaves

After splitting users by age, the all-Atom-Count group is pure and becomes a leaf predicting Atom Count. The remaining mixed group can be split by platform, yielding leaves that predict Beehive Count for Android and Check Mate Mate for iPhone. section 9.4 section 9.6

How Grokking Machine Learning, Second Edition covers it

How deep it goes
Explains leaf creation, purity, stopping conditions, majority-label predictions, and a classifier tie case.
Examples
Uses jacket choices, app recommendations, and student-admissions classification trees.
What it assumes
Introduces leaves alongside binary-tree roots, branches, and decision nodes.
What you can do after
Evaluate/understand a tree’s prediction by tracing to a leaf and reading its associated label.
How it connects
Connects leaf nodes to decision trees, root nodes, decision nodes, tree depth, Gini index, entropy, and overfitting.

Also explained in

Compare how 14 books explain leaf node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning, Second Edition. The section links point to the parts of the book it draws on.