Weighted Gini
Learn how weighted Gini combines impurity across left and right child nodes.
A single split creates two child groups—a left group and a right group. Weighted Gini combines their impurity scores into one number the tree can compare.
Big idea
After a split, each child may have a different Gini score and a different number of samples. A tiny but very pure group should not outweigh a large mixed group.
Weighted Gini averages the left and right Gini values, giving more weight to the side with more samples. The tree uses this score to judge whether a split is good.
Formula
Here n is the total number of samples in the parent node, and nleft and nright are the sizes of each child.
Split rules:
- Left: samples where x≤t
- Right: samples where x>t
Worked example
On our 8-sample practice dataset, splitting Feature 0 at threshold t=2.5 gives:
| Group | Samples | Class Mix | Gini | Weight |
|---|---|---|---|---|
| Left (x≤2.5) | 4 | 3 class 0, 1 class 1 | 0.375 | 4/8=0.5 |
| Right (x>2.5) | 4 | 4 class 1 | 0.000 | 4/8=0.5 |
Common mistake
Averaging Gini values without weighting by sample count. Two children of unequal size need the nnleft and nnright factors—otherwise a small group can skew the result.
Key takeaway
Weighted Gini is how a decision tree scores one candidate split. Lower weighted Gini means the split produced cleaner child groups overall.
Use the Weighted Gini Calculator below to adjust left and right class counts and see the weighted score change.
Interactive
Weighted Gini Split Calculator
Compare left and right child groups to see how weighted Gini combines impurity across a split.
Left group
Right group
Left total
10
Right total
10
Total samples
20
Gini(left)
0.480
Gini(right)
0.320
Weighted Gini formula
(10 / 20) × 0.480 + (10 / 20) × 0.320 = 0.400
(nleft / n) × Gini(left) + (nright / n) × Gini(right)
Weighted Gini
0.400
Practice
Try It Yourself
Open the practice lab to complete the starter code in the notebook.
Knowledge Check
Quick Quiz
Weighted Gini accounts for child group size by:
Summary
Key Takeaways
- A split creates left and right child groups.
- Weighted Gini averages child impurities by group size.
- The best split minimizes weighted Gini impurity.