Decision Tree Rules, Root Node & Pruning (CBSE AI Code 417)

⚡ Direct Answer & Key Takeaway

In CBSE AI Code 417 (Part B, 40 marks), a Decision Tree classifies data from top to bottom starting at the Root Node—the feature with the highest Information Gain and lowest weighted Entropy. Internal Decision Nodes test remaining attributes along Branches until pure or stopping Leaf Nodes return final class labels. Pruning trims overly deep branches that memorize training noise, preventing overfitting and boosting accuracy on unseen test sets.

1. Anatomy of a Decision Tree: Root, Branches, and Leaves

A Decision Tree mimics a top-down flowchart constructed automatically from labeled training rows. At the very top sits a single Root Node representing the entire dataset before any split occurs; selecting the strongest attribute here minimizes tree depth right away. Outgoing arrows called Branches denote specific attribute outcomes—such as Humidity = High or Temperature <= 30°C—routing subsets of rows into child Decision Nodes for further testing. Splitting stops at terminal Leaf Nodes, which have no outgoing arrows and carry the predicted class decision (for example, 'Play Tennis = Yes'). During CBSE Class 10 (Code 417) Part B board exams, questions routinely ask students to trace a query record from Root to Leaf and justify why an attribute belongs at the top versus lower levels.

  • Root Node sits at depth 0 and holds the entire unfiltered training dataset.
  • Branches represent conditional test outcomes routing rows toward child Decision Nodes.
  • Leaf Nodes terminate recursion and return the final predicted class or majority vote.

2. Shannon Entropy and Information Gain for Choosing Splits

To decide which feature earns the Root Node slot, algorithms like ID3 measure node impurity using Shannon Entropy: $H(S) = -\sum p_i \log_2(p_i)$. A perfectly pure subset containing only positive outcomes has Entropy 0, whereas an even 50-50 binary split reaches maximum disorder at Entropy 1.0. For a candidate attribute $A$, the tree computes Information Gain as parent Entropy minus the weighted average Entropy of its child branches: $IG(S, A) = H(S) - \sum \frac{|S_v|}{|S|} H(S_v)$. Consider 10 training days with 5 Yes and 5 No outcomes ($H(S) = 1.0$). If splitting on Weather produces a Sunny branch (4 Yes, 0 No; $H=0$) and a Rainy branch (1 Yes, 5 No; $H=0.65$), the weighted child entropy is $0.6 \times 0.65 = 0.39$, yielding Information Gain $1.0 - 0.39 = 0.61$.

  • Entropy ranges from 0.0 (pure single-class node) to 1.0 (50-50 balanced binary mix).
  • Information Gain equals Parent Entropy minus weighted average Child Entropy.
  • ID3 greedily picks the attribute delivering the maximum Information Gain at each step.

3. Overfitting Prevention via Pre-Pruning and Post-Pruning

Left unrestricted, a Decision Tree keeps splitting until every leaf holds a single training row, achieving 100% training accuracy while failing badly on fresh test data—a classic failure mode called overfitting. Overfit trees memorize random measurement glitches and rare edge cases instead of generalizable patterns. Pruning remedies this in two ways taught across CBSE AI 417 Practical (50 marks) labs and Class 12 (Code 843) modeling units. Pre-pruning halts growth early using stopping criteria such as `max_depth`, `min_samples_split`, or minimum Information Gain thresholds. Post-pruning first grows a full tree and then collapses weak subtrees back into majority-class leaves whenever validation error drops. A well-pruned tree stays compact, faster to interpret, and far more reliable on board-exam generalization tasks.

  • Unpruned trees memorize outlier noise, widening the gap between training and test accuracy.
  • Pre-pruning enforces constraints like max_depth or min_samples_split before splits form.
  • Post-pruning trims low-utility branches after full growth using validation checks.

4. Decision Tree Root Entropy, Information Gain & Pre-Pruning Check

import math

def entropy(pos, neg):
    total = pos + neg
    if total == 0 or pos == 0 or neg == 0:
        return 0.0
    p1, p2 = pos / total, neg / total
    return -(p1 * math.log2(p1) + p2 * math.log2(p2))

parent_h = entropy(5, 5)
# Candidate 1: Weather -> Sunny (4 Yes, 0 No), Rainy (1 Yes, 5 No)
ig_weather = parent_h - (4 / 10) * entropy(4, 0) - (6 / 10) * entropy(1, 5)
# Candidate 2: Wind -> Weak (3 Yes, 3 No), Strong (2 Yes, 2 No)
ig_wind = parent_h - (6 / 10) * entropy(3, 3) - (4 / 10) * entropy(2, 2)

root = "Weather" if ig_weather >= ig_wind else "Wind"
min_samples_split = 5
sunny_split = "Leaf (Play=Yes)" if 4 < min_samples_split else "Continue Split"

print(f"Parent Entropy: {parent_h:.3f}")
print(f"IG(Weather): {ig_weather:.3f} | IG(Wind): {ig_wind:.3f}")
print(f"Chosen Root Node: {root} | Sunny Branch Status: {sunny_split}")

Verified Console / Dry-Run Output:

Parent Entropy: 1.000
IG(Weather): 0.610 | IG(Wind): 0.000
Chosen Root Node: Weather | Sunny Branch Status: Leaf (Play=Yes)

5. Worked Decision Tree Entropy & Information Gain Split Table

Tree Component / MetricClass Mix or ConditionEntropy / Gain ValueTree Action Taken
Parent Root Dataset (S)5 Yes, 5 No (10 rows)Entropy H(S) = 1.000Maximum impurity; evaluate candidate splits
Sunny Branch (Weather)4 Yes, 0 No (4 rows)Entropy = 0.000Pure subset; convert directly to Leaf (Yes)
Rainy Branch (Weather)1 Yes, 5 No (6 rows)Entropy = 0.650Impure; split further unless depth limit reached
Candidate Split: WindWeak (3Y/3N), Strong (2Y/2N)IG(Wind) = 0.000Rejected in favor of Weather (IG = 0.610)
🎯 1-on-1 Live Mentorship & Free Study Kit

Master Decision Trees With Free 1:1 CBSE AI Practice

Practice Decision Tree rule tracing, Shannon Entropy numericals, and pruning strategies in 1-on-1 or 1:4 Micro-Pods at 4Achievers Junior.

💬 WhatsApp Now
🔒 Instant WhatsApp notes + free 60-min 1-on-1 trial session
Confirmed! Our Senior Mentor is sending your study kit & free 1-on-1 demo link on WhatsApp now.

6. Common Mistakes & Top Scorer Tips

  • Avoid Mistake: Picking the feature with the highest child Entropy as the Root Node instead of the highest Information Gain.
  • Avoid Mistake: Confusing internal Decision Nodes (which still split further) with terminal Leaf Nodes (which output final labels).
  • Avoid Mistake: Growing an unpruned tree to 100% training accuracy and failing to notice severe test-set overfitting.
  • Examiner / Mentor Tip: Label Root Node, Decision Node, Branch, and Leaf Node cleanly when sketching trees in Part B (40 marks).
  • Examiner / Mentor Tip: Write the rule-tracing path in standard IF...AND...THEN format when answering 3-mark scenario questions.
  • Examiner / Mentor Tip: Explain overfitting with a real example: tuning `max_depth` in scikit-learn during Practical (50 marks) evaluation.

7. Interactive Concept Check Quiz

Question: In a CBSE AI dataset, splitting on Weather yields Information Gain 0.610 while splitting on Wind yields 0.000. How should the Decision Tree choose its Root Node?

8. Frequently Asked Questions

What is the Entropy of a completely pure Leaf Node in a Decision Tree?
A node containing a 100% homogeneous class (all Yes or all No) has Shannon Entropy equal to 0, meaning no further split is needed.
How do pre-pruning and post-pruning differ?
Pre-pruning stops tree expansion early using constraints like max_depth or min_samples_split, while post-pruning grows a full tree first and trims weak branches using validation accuracy.
Why does the Root Node matter so much in CBSE AI 417 Decision Tree questions?
Choosing the highest Information Gain attribute at the Root Node creates pure subsets sooner, resulting in a shorter, cleaner, and less overfit tree.

Explore Related Lessons & Free Interactive Tools

Free 1-on-1 Session

Book a Free Demo Class