Created
Apr 28, 2025
Last Modified
2 weeks ago

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

ID3 decision tree initial structure showing root node Age splitting into categories old, mid, and new

, 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"

ID3 decision tree final structure with Age as root and Competition as child node leading to Up and Down classification

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"