Machine Learning II: Decision Trees and Information Theory (ID3)
Overview of Decision Trees
Learning Decision Trees: Inductive learning is a form of supervised learning that involves learning from examples. It is considered one of the simplest yet most successful forms of learning algorithms.
Functionality: A decision tree takes a set of properties (attributes) as input and provides a classification output (e.g., a "YES/NO" decision).
Structure of the Tree:
Non-leaf nodes: Represent an attribute test.
Links/Branches: Labeled with possible values associated with the attribute.
Leaf nodes: Represent the final classification or decision (e.g., Yes or No).
Expressiveness: Decision trees are fully expressive within the class of propositional languages.
Goal: The aim of decision tree learning is to find a small tree that is consistent with the training examples provided by (recursively) choosing the "most significant" attribute as the root of the (sub)tree.
Case Study: Restaurant Waiting Decision
Goal Predicate: The target variable is
WillWait(Yes/No).Attributes Used for Decision Making:
Alternate: Whether there is a suitable alternative restaurant nearby.
Bar: Whether the restaurant has a comfortable bar area to wait in.
Fr/Sat: True on Fridays and Saturdays.
Hungry: Whether the patrons are currently hungry.
Patrons: How many people are in the restaurant (Values:
None,Some,Full).Price: The price range of the restaurant (Values:
$,).Raining: Whether it is raining outside.
Reservation: Whether a reservation was made.
Type: Kind of food served (
French,Italian,Thai,Burger).WaitEstimate: The host's estimated wait time (
0-10,10-30,30-60,>60minutes).
Complexity Management: While a dataset may include 10 attributes, a learned tree might be substantially simpler than the "true" tree if a more complex hypothesis isn't justified by a small amount of data. For instance, a model might only use 4 attributes (
Patrons,Hungry,Type, andFri/Sat) instead of all 10 to classify 12 examples.
Information Theory and the ID3 Algorithm
ID3 (Iterative Dichotomiser 3): An algorithm used to choose the best attribute for splitting the data at each node using information theory.
Entropy (Information Content): A formula used to calculate the homogeneity (purity) of a sample.
A completely homogeneous sample (all same class) has an entropy of .
An equally divided sample (e.g., half positive, half negative) has an entropy of .
Entropy Formula (for a set with positive and negative examples):
Performing Logarithm Base 2: Since most calculators use Log base 10, the conversion formula is:
Information Gain (IG): This is the measurement of the decrease in entropy after a dataset is split on an attribute.
First, calculate the entropy of the total dataset.
Split the dataset on different attributes.
Calculate the entropy for each resulting branch.
Add branch entropies proportionally to get the total entropy for the split.
Subtract the split entropy from the original entropy to find the gain.
Decision Criterion: The attribute that yields the largest Information Gain is chosen for the decision node.
Recursion: If a branch has an entropy of 0, it becomes a leaf node. If not, the ID3 algorithm is run recursively on that branch until all data is classified.
Case Study: The Simpsons Classification
Objective: Classify characters as Male (M) or Female (F).
Initial Dataset (9 Samples):
Homer: Hair 0", Weight 250, Age 36, Class M
Marge: Hair 10", Weight 150, Age 34, Class F
Bart: Hair 2", Weight 90, Age 10, Class M
Lisa: Hair 6", Weight 78, Age 8, Class F
Maggie: Hair 4", Weight 20, Age 1, Class F
Abe: Hair 1", Weight 170, Age 70, Class M
Selma: Hair 8", Weight 160, Age 41, Class F
Otto: Hair 10", Weight 180, Age 38, Class M
Krusty: Hair 6", Weight 200, Age 45, Class M
Step 1: Calculate Total System Entropy:
(Females), (Males), Total = 9.
Step 2: Evaluate Attribute Splits:
Hair Length Split (Threshold: inches):
: 1 Female, 3 Males.
> 5": 3 Females, 2 Males.
Weight Split (Threshold: kg):
: 4 Females, 1 Male.
> 160: 0 Females, 4 Males.
Age Split (Threshold: ):
: 3 Females, 3 Males.
> 40: 1 Female, 2 Males.
Step 3: Root Node Selection:
Since Weight has the highest IG (), it is chosen as the root of the decision tree.
Step 4: Sub-Tree Development (Weighted branch ):
The subset contains: Marge, Bart, Lisa, Maggie, Selma (4F, 1M). Previous .
Testing Age < 30:
< 30: 2F, 1M.
: 2F, 0M.
Testing Hair Length \le 2":
: 0F, 1M (Bart).
> 2": 4F, 0M.
Result: Hair Length is chosen as the next attribute because its IG () is higher than Age ().
Final Decision Model and Rules
Final Decision Tree Strategy:
Test: Is Weight greater than ?
If No (): Test: Is Hair Length less than or equal to ?
If Yes: Classify as Male.
If No: Classify as Female.
If Yes (> 160): Classify as Male.
Rule Conversion: Decisions can be converted into standard conditional logic:
\text{If Weight > 160, then Male}
Prediction Practice:
Comic Guy (Hair 8", Weight 290, Age 38): Classified as Male because Weight is > 160.