liveBook · Manning

Leaf node

As explained in Grokking Machine Learning

A terminal decision-tree node with no outgoing branches that contains the resulting decision or prediction.

Should you wear a jacket? A decision tree answers by following yes-or-no branches until it reaches a leaf node. A leaf has no outgoing branches: it is where the tree stops asking questions and makes its decision. Nodes that do ask questions are called decision nodes. section 9.0

A decision stump shows the simplest arrangement: one question at the root and two leaves, one for each answer. In a larger tree, a branch may lead to another question instead. The depth of a tree is the length of its longest path from the root to a leaf, counted in branches. section 9.0

When does a leaf stay a leaf?

Suppose a tree recommends an app using a person's age and phone platform. Splitting by age puts all three young users, who downloaded the same app, in one group. That group is *pure*, so its node becomes a leaf that predicts that app. The adult group still has different app labels, so it can be split by platform. After that split, the resulting groups are pure too. section 9.2

A leaf need not be pure to make a prediction. When comparing candidate splits, the prediction at each leaf can be the most common label among the samples there. Accuracy measures how often those predictions are correct; Gini index and entropy offer other ways to compare splits. Repeatedly splitting a group can turn what was a leaf into a decision node with new leaves below it. section 9.2

Figure 9.16 We can split the right leaf of the tree in figure 9.15 using platform and obtain two pure datasets. Each one of them has an accuracy of 100% and a Gini index and entropy of 0.

See how splitting the remaining mixed leaf by platform produces two pure groups, each ready to be a final leaf. section 9.2

Try drawing a jacket-decision stump with one question and two leaves. Then choose one leaf and add a second question beneath it. Which decisions now sit at the leaves, and how has the tree's depth changed? section 9.0

How Grokking Machine Learning covers it

How deep it goes
Defines leaves geometrically and works through pure groups, majority-label predictions, and splitting a leaf again.
Examples
Uses a jacket decision stump and an app-recommendation tree split first by age, then by phone platform.
What it assumes
Introduces nodes, branches, and binary trees through yes-or-no questions before applying leaf nodes to classification.
What you can do after
Build it from scratch by splitting mixed groups, assigning predictions to leaves, and stopping when groups are pure.
How it connects
Connects leaf nodes to decision trees, decision stumps, tree depth, classification accuracy, Gini index, and entropy.

Also explained in

Compare how 10 books explain leaf node →

Related concepts

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