Constructing a Simple Decision Tree (ID3) with Attribute Selection for a Small Dataset
We will build a decision tree for the dataset with features Weather and Temp to predict the label Play?. The dataset is:
| Weather | Temp | Play? |
|---|---|---|
| Sunny | Hot | No |
| Sunny | Cool | Yes |
| Rainy | Cool | Yes |
| Rainy | Hot | No |
A standard way to “construct a simple decision tree” from categorical data is the ID3 criterion, which chooses the attribute that maximizes Information Gain based on Entropy.
Key selection idea: choose the attribute that best separates the classes (Yes/No) in the resulting subsets.
Note: I attempted web research for authoritative formulas, but the web-search tool is unavailable due to a usage-limit error; therefore, the mathematics below is derived directly from the standard ID3 definitions (entropy and information gain).
Decision Tree (ID3) Intuition: Entropy and Information Gain
Step-by-step: compute entropy and choose the best attribute (ID3-style)
- 1Step 1
At the root, there are 2 instances with Play?=Yes and 2 instances with Play?=No, so the class distribution is (Yes:2, No:2).
- 2Step 2
Use . Here and , so .
- 3Step 3
Partition by Weather: (Sunny: 2 records: {No, Yes} ⇒ one Yes and one No) and (Rainy: 2 records: {Yes, No} ⇒ one Yes and one No). Each subset has entropy 1.
- 4Step 4
. Since both subsets have entropy 1 and each has size 2, the weighted entropy is . Hence .
- 5Step 5
Partition by Temp: (Hot: 2 records: {No, No} ⇒ all No) and (Cool: 2 records: {Yes, Yes} ⇒ all Yes). Each subset is pure, so entropy is 0.
- 6Step 6
.
- 7Step 7
Because is greater than , choose Temp as the root split. Then create leaves: if Temp=Hot ⇒ Play?=No; if Temp=Cool ⇒ Play?=Yes.
- 8Step 8
The resulting tree has one internal node (Temp) and two leaves.
1) Entropy and information gain (computed explicitly)
Let be the full dataset and its entropy.
- Root: ,
Split on [Weather]{def="A categorical input attribute used to split data in a decision tree}
- Sunny subset has 1 Yes and 1 No ⇒ entropy:
- Rainy subset has 1 Yes and 1 No ⇒ entropy:
- Weighted entropy:
- Information gain:
Split on [Temp]{def="A categorical input attribute used to split data in a decision tree}
- Hot subset has all No ⇒ entropy:
- Cool subset has all Yes ⇒ entropy:
- Weighted entropy:
- Information gain:
2) Constructed decision tree
The best attribute is Temp because it yields the highest Information Gain () and produces pure child nodes (entropy ).
Information Gain by Attribute
ID3-style selection prefers the attribute with larger information gain.
Pro Tip: When IG is 0
If an attribute split does not change class purity (both subsets remain equally mixed), its weighted entropy equals the parent entropy, so . In this dataset, Weather leaves the class composition unchanged within each Weather value.
Beware: Decision trees can overfit on tiny datasets
With only 4 samples, many splits may look “perfect.” In practice, you’d validate using cross-validation or pruning; but for this exercise, we correctly follow the information-gain criterion.
Attribute Selection Criteria (Explanation)
How to Construct the Tree (Conceptual Roadmap)
Compute root impurity
1Calculate root entropy from class counts."
Try each candidate attribute
2Split data by attribute values and compute weighted child entropies."
Select best attribute (max gain)
3Choose the attribute with largest information gain."
Stop when nodes are pure (or no attributes remain)
4If a subset has only one class, output a leaf label."
Decision Tree Attribute Selection (ID3) Flashcards
Knowledge Check
At the root, there are 2 'Yes' and 2 'No'. What is the entropy ?