Information Gain
Definition: Information gain measures the reduction in entropy (disorder/uncertainty) achieved by splitting a dataset based on a particular attribute or feature.
Formula:
Information Gain = Entropy(parent) - Weighted Average of Entropy(children)
How it works:
- Calculates entropy before and after a split
- Higher information gain means the split creates more homogeneous subsets
- Used primarily in ID3 and C4.5 decision tree algorithms
- Always ranges from 0 to log₂(number of classes)
Advantages:
- Intuitive measure of how much information a feature provides
- Works well with categorical features
- Provides clear ranking of feature importance
Disadvantages:
- Biased toward features with more distinct values
- Can lead to overfitting with high-cardinality features
- Computationally expensive for continuous variables
Gini Index (Gini Impurity)
Definition: Gini index measures the probability of incorrectly classifying a randomly chosen element if it were randomly labeled according to the class distribution in the dataset.
Formula:
Gini = 1 - Σ(pᵢ)² where pᵢ is the probability of class i
How it works:
- Ranges from 0 (pure node) to 0.5 (maximum impurity for binary classification)
- Lower Gini index indicates better split
- Used in CART (Classification and Regression Trees) algorithm
- Measures how often a randomly chosen element would be incorrectly labeled
Advantages:
- Computationally efficient (no logarithms)
- Less biased toward high-cardinality features compared to information gain
- Works well for binary and multi-class problems
- Faster to compute than entropy-based measures
Disadvantages:
- Less intuitive interpretation than information gain
- May not perform as well as information gain in some scenarios
- Can still be affected by class imbalance
Key Differences
Calculation Speed: Gini index is faster since it avoids logarithmic calculations that entropy requires.
Bias: Information gain tends to favor features with more categories, while Gini index is less prone to this bias.
Usage: Information gain is used in ID3/C4.5 algorithms, while Gini index is the default in CART and Random Forest implementations.
Interpretation: Information gain has a clearer theoretical foundation in information theory, while Gini index has a more probabilistic interpretation.
Performance: Both typically produce similar results in practice, though information gain may perform slightly better in some cases with categorical data.