MACHINE LEARNING/Student Engineering Notebook
Page 06·notes
DECISION TREES (ID3, CART) & ENSEMBLE METHODS—~32 MIN READ

Decision Trees: Shannon Entropy, Information Gain & Gini Index

“Impurity splitting metrics, ID3 vs CART, continuous feature thresholds, and cost-complexity pruning.”

1.The Mathematics of Tree Splitting Criteria

Decision trees recursively partition input feature space into orthogonal hyper-rectangles using greedy impurity reduction.

Entropy vs Gini Impurity:

Both measure the impurity of a node. Gini impurity is computationally faster because it avoids logarithmic evaluations (log_2). For a binary classification task:

- Entropy = - [ p log_2(p) + (1-p) log_2(1-p) ] (peaks at 1.0 bit when p=0.5).

- Gini = 1 - [ p^2 + (1-p)^2 ] = 2p(1-p) (peaks at 0.5 when p=0.5).

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION

2. Worked Practice Problem: Information Gain on Discrete Features

⚠️ Pitfall Warning:

Remember to weight each child entropy by its proportion |S_v| / |S|.

Problem: A dataset of 10 samples has 6 Positive (+) and 4 Negative (-) instances. A feature splits it into Left (4+, 1-) and Right (2+, 3-). Compute the Information Gain.

Step 1: Compute Parent Entropy H(S):

p+ = 6/10 = 0.6, p- = 4/10 = 0.4

H(S) = - [ 0.6 log2(0.6) + 0.4 log2(0.4) ] = - [ 0.6(-0.737) + 0.4(-1.322) ] = 0.442 + 0.529 = 0.971 bits.

Step 2: Compute Left Child Entropy H(S_L) [4+, 1-]:

p+ = 4/5 = 0.8, p- = 1/5 = 0.2

H(S_L) = - [ 0.8log2(0.8) + 0.2log2(0.2) ] = - [ 0.8(-0.322) + 0.2(-2.322) ] = 0.258 + 0.464 = 0.722 bits.

Step 3: Compute Right Child Entropy H(S_R) [2+, 3-]:

p+ = 2/5 = 0.4, p- = 3/5 = 0.6

H(S_R) = 0.971 bits (same distribution as parent).

Step 4: Compute Weighted Child Entropy:

E[H] = (5/10) H(S_L) + (5/10) H(S_R) = 0.5 (0.722 + 0.971) = 0.5 1.693 = 0.8465 bits.

Step 5: Compute Information Gain:

Gain = H(S) - E[H] = 0.971 - 0.8465 = 0.1245 bits.

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: This is the Wind attribute in Mitchell's PlayTennis example; ID3 picks the attribute with the highest gain.

Worked example: information gain

Problem Statement:
A node has 9 positive and 5 negative examples. A split gives children [6+, 2−] and [3+, 3−]. Find the information gain.
Step 1: Parent entropy

H(9/14, 5/14).

↳ Result: ≈ 0.940
Step 2: Child entropies

H(6/8, 2/8) ≈ 0.811 and H(3/6, 3/6) = 1.

Step 3: Weighted child entropy

(8/14)·0.811 + (6/14)·1.

≈ 0.892
Step 4: Gain

0.940 − 0.892.

≈ 0.048
Final Answer:Information gain ≈ 0.048
STUDENT PRACTICE · CONCEPT DRILL

Practice: test yourself

Original practice questions in the GATE style, with worked explanations. Not past-paper questions.

Problem 1 · FOUNDATION

What is the Gini impurity of a node that is 50% one class and 50% the other?

Problem 2 · FOUNDATION

What is the entropy (base 2) of a node with 4 positive and 4 negative examples?

Problem 3 · TRICKY

Why does information gain favour attributes with many values (like an ID number)?

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Classification and Regression Trees ·
LECTURE SERIES