Machine Learning Basics
A node of a decision tree holds 6 data points of class A and 4 of class B. What is the Gini impurity of this node?
- A0.24
- B0.40
- C0.48
Show answer and explanation
Answer: C. 0.48
Gini impurity is computed as 1 − Σp², where p is the proportion of each class. Class A has a proportion of 0.6 and class B 0.4, so the impurity is 1 − (0.36 + 0.16) = 0.48. A node with only one class has an impurity of 0, and with two classes the maximum, 0.5, occurs when they are half and half. A decision tree splits the data by choosing the feature and threshold that minimize the weighted average impurity (Gini impurity or entropy) of the child nodes after the split.
- A. This is 0.6 × 0.4 = 0.24, the two-class Gini impurity 2 × 0.6 × 0.4 without the factor of 2.
- B. This is the proportion of the minority class, the error rate when classifying by majority vote.
- C. Correct. 1 − (0.6² + 0.4²) = 0.48.