• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Knowing that Information Gain measures uncertainty reduction is conceptual; implementing a decision tree requires the precise computational steps to evaluate every candidate attribute at every node.

Core Idea

Information Gain calculation involves computing the parent entropy, calculating each child’s entropy after a hypothetical split, weighting each child entropy by its proportion of the total data, and subtracting this weighted sum from the parent entropy.

How It Works

Detailed calculation procedure:

  1. Compute parent entropy: Calculate Entropy(S) for the entire dataset at the current node
  2. For each candidate attribute A: a. Partition S into subsets SvS_v for each value vv of attribute A b. Calculate Entropy(SvS_v) for each subset c. Compute the weighted average: SvS×Entropy(Sv)\sum \frac{|S_v|}{|S|} \times Entropy(S_v) d. Subtract from parent entropy: Gain(S,A)=Entropy(S)weighted averageGain(S, A) = Entropy(S) - \text{weighted average}
  3. Select the attribute with maximum Gain

Worked example from source (split on attribute Y):

Given dataset with 3 features (X, Y, Z) and 2 classes (I, II):

XYZC
111I
110I
001II
100II
  • Parent entropy: 2 of class I, 2 of class II → Entropy = 1.0
  • Split on Y:
    • Y=1: 2 instances, both class I → Entropy = 0.0
    • Y=0: 2 instances, both class II → Entropy = 0.0
    • Weighted average: (2/4) × 0.0 + (2/4) × 0.0 = 0.0
    • Gain(Y) = 1.0 - 0.0 = 1.0 (maximum possible)

Since splitting on Y produces perfectly pure children, Y is chosen as the root node, and no further splits are needed.

Visual Explanation

ig_calculation parent Step 1: Parent Entropy H(S) = 1.0 (2I, 2II) split Step 2: Split on Y Y=1: {I,I} | Y=0: {II,II} parent->split child_e Step 3: Child Entropies H(Y=1) = 0, H(Y=0) = 0 split->child_e weighted Step 4: Weighted Avg (2/4)×0 + (2/4)×0 = 0 child_e->weighted gain Step 5: Gain 1.0 - 0.0 = 1.0 (MAX) weighted->gain

Key Properties

  • Per-attribute evaluation: Must be computed for every candidate attribute at every node
  • Monotonic: Adding more attributes to the dataset cannot decrease the maximum achievable IG
  • Computationally intensive: Requires entropy calculation for each candidate split at each node
  • Greedy: Computed locally without considering future splits

Connections

Edge Cases & Gotchas

  • Division by zero: If |S| = 0 (empty node), IG is undefined — the node should be a leaf
  • All same values: If an attribute has the same value for all instances, only one child exists and IG = 0
  • Precision accumulation: Repeated floating point operations can accumulate rounding errors in deep trees
  • Tie-breaking: Multiple attributes may have identical IG; a deterministic tie-breaking rule is needed