1. Build Your Decision Tree

This page explains how a classification tree turns recorded examples into branching questions.

In Section C, you compared options and explained a choice. A tree makes a different part of the reasoning visible: which question comes next, and where does each answer lead?

In Section B, you saw trees that map choices and uncertain outcomes. This lesson develops classification trees: they use the characteristics of a case to assign it to a category. The weather example classifies conditions as “Play” or “Don’t play.” This gives us a rule to follow, while the matrix in Section C helps weigh the consequences of a choice.

To follow a tree, we need to recognise its starting question, the paths it creates, and its final categories. The labels below describe those parts.

The Parts of a Tree

PartRole
RootThe first question and entry point at the top of the tree.
Question nodesTests that split cases into different paths.
BranchesPossible answers to each question.
LeavesFinal outcomes at the end of a path.
ClassesThe possible output categories.
Weather classification tree showing outlook, humidity, and wind questions

Now that you can identify the parts, follow how they connect. A complete path tells us which conditions lead to a particular category.

2. Read a Tree as Decision Rules

Follow each path from the root to a leaf to form an if–then rule. In the weather example, “outlook” means sunny, overcast, or rainy conditions. Humidity measures moisture in the air. Read ≤ 70 as “70 or less” and > 70 as “more than 70.”

ConditionsResult
Sunny and humidity ≤ 70Play
Sunny and humidity > 70Don’t play
OvercastPlay
Rain and windyDon’t play
Rain and not windyPlay

The table turns the diagram’s paths into rules. Try following one of those paths yourself before opening the answer.

Quick Check

It is sunny, humidity is 72, and it is windy. Which path would you follow, and what is the result?

Check Your Answer

Follow Sunny → Humidity > 70 → Don’t play. Wind is not needed on this branch.

Explore the Original 14-Day Dataset

A dataset is a collection of recorded examples. These 14 rows show the weather conditions and the “Play” label for each day. Compare the rows with the rules above.

DayOutlookHumidityWindyPlay
1Sunny34YesPlay
2Sunny15NoPlay
3Sunny72YesNot Play
4Sunny86YesNot Play
5Sunny98NoNot Play
6Overcast25YesPlay
7Overcast30YesPlay
8Overcast75NoPlay
9Overcast57NoPlay
10Rain72NoPlay
11Rain88NoPlay
12Rain93NoPlay
13Rain65YesNot Play
14Rain59YesNot Play

You can now follow an existing tree. But how do we choose its questions in the first place? Recorded examples can help us identify questions that separate the categories.

3. Build a Tree from Data

A tree can be built by hand or learned from examples using an algorithm: a step-by-step procedure. ID3 (Iterative Dichotomiser 3) is one such algorithm. It uses information gain, a measure of how much a question reduces the mixture of categories, to choose a split.

  1. Identify the target class: the category you want to predict, such as Play/Don’t play.
  2. Compare possible attributes (recorded characteristics, such as outlook) and how well they separate the categories.
  3. Split on the attribute with the greatest information gain.
  4. Repeat within mixed branches until no further split is needed or possible.

Key idea: ID3 makes the best local choice at each split—a greedy strategy. This does not guarantee the best overall tree, and fitting known examples does not guarantee accuracy on new ones.

Choosing questions also affects the shape of a tree. Some cases may reach an answer quickly while others need several questions. Consider how that affects clarity.

Tree Forms and Trade-offs

Balanced and deeper decision tree forms

A more balanced tree distributes questions more evenly across paths. An uneven tree may reach some answers quickly while requiring more questions for others. Consider clarity, the longest path, and how well the rules work on new cases.

Going Further: Entropy and Information Gain

Entropy measures how mixed the target classes are. A branch containing only one class has entropy 0; a mixed branch has higher entropy.

H(S) = −Σ pᵢ log₂(pᵢ), where pᵢ is the proportion of examples in class i. Σ means add the terms for all classes; log₂ is a base-2 logarithm used in this calculation. Terms with pᵢ = 0 contribute 0.

Information gain = entropy before the split − weighted entropy after the split. Weight each resulting group by its share of the original dataset.

A question with greater information gain separates the classes more clearly. You can use this principle without doing the calculations in the activity on the next page.

You have followed a tree and seen how questions can separate categories. Next, build your own tree from the lesson’s fictional stock dataset.