ID3 Algorithm
Algorithm
Construct the decision tree using the algorithm for the given data set.
S.no | Age | Competition | Type | Profit (Class) |
|---|---|---|---|---|
1 | Old | Yes | Soft | Down |
2 | Old | No | Soft | Down |
3 | Old | No | Hard | Down |
4 | Mid | Yes | Soft | Down |
5 | Mid | Yes | Hard | Down |
6 | Mid | No | Hard | Up |
7 | Mid | No | Soft | Up |
8 | New | Yes | Soft | Up |
9 | New | No | Hard | Up |
10 | New | No | Soft | Up |
π§ Step 1: Initial Entropy of Dataset
Where:
Total = 10
Down = 5 (1 to 5)
Up = 5 (6 to 10)
So:
β Entropy() = 1
Step 2: Calculate Information Gain for all attributes
Attribute 1: Age (Old, Mid, New)
Old: = [Down, Down, Down]
Mid : = [Down, Down, Up, Up]
New: = [Up, Up, Up]
β Gain(Age) = 0.6
Attribute 2: Competition (Yes, No)
Yes : = [Down, Down, Down, Up]
No: = [Down, Down, Up, Up, Up, Up]
β Gain(Competition) = 0.125
Attribute 3: Type (Soft, Hard)
Soft: = [Down, Down, Down, Up, Up, Up]
Hard : = [Down, Down, Up, Up]
β Gain(Type) = 0
Find the maximum Gain
β Gain(Age) = 0.6
β Gain(Competition) = 0.125
β Gain(Type) = 0
Age gives the highest gain (0.6).
Thus, "Age" will be placed at the root of the Decision Tree.
The Decision Tree Formation

, a subset of for which Age = Old
Age | Competition | Type | Profit (Class) |
|---|---|---|---|
Old | Yes | Soft | Down |
Old | No | Soft | Down |
Old | No | Hard | Down |
Observation:
All 3 examples β Profit = Down
β Pure group!
thus
Leaf Node = "Down"
a subset of for which Age = Mid
Age | Competition | Type | Profit (Class) |
|---|---|---|---|
Mid | Yes | Soft | Down |
Mid | Yes | Hard | Down |
Mid | No | Hard | Up |
Mid | No | Soft | Up |
Observation:
2 examples β Down
2 examples β Up
β
Mid group is impure (entropy = 1).
Further splitting is needed.
π·Attribute 1: Competition(Yes, No)
Yes: = [Down, Down]
No: = [Up, Up]
β Gain(Competition) = 1
π·Attribute 2: Type(Soft, Hard)
Soft: = [Down, Up]
Hard : = [Down, Up]
β Gain(Type) = 1
Since the Gain is maximum for the attribute, putting the competition at Node 2
a subset of for which Age = New
Age | Competition | Type | Profit (Class) |
|---|---|---|---|
New | Yes | Soft | Up |
New | No | Hard | Up |
New | No | Soft | Up |
All 3 examples β Profit = Up
β Pure group!
Leaf Node = "Up"

All the corresponding class labels are down in
β
Pure group!
Leaf Node = "Down"
All the corresponding class labels are up in
β
Pure group!
Leaf Node = "Up"
