Build the Root
Compare all candidate splits and choose the root of the tree.
A decision tree does not pick the first reasonable split—it evaluates every candidate and chooses the winner for the root node.
Big idea
The splitting process repeats the same recipe at every node:
- For each feature, generate all midpoint thresholds.
- For each (feature, threshold) pair, split the data into left and right groups.
- Compute weighted Gini for that split.
- Pick the pair with the smallest weighted Gini.
That winning split becomes the node's decision. Impure child groups are split again using the same process.
Formula
For each candidate feature and threshold:
Weighted Gini=nnleft⋅Gini(left)+nnright⋅Gini(right)The best split minimizes this score:
Best split=argfeature,tminWeighted GiniIf two splits tie, libraries use a consistent tie-breaking rule (often preferring the earlier feature).
Worked example
On the 8-sample practice dataset, the root node compares every candidate:
| Feature | Threshold | Weighted Gini | Notes |
|---|---|---|---|
| Feature 0 | 1.5 | 0.208 | |
| Feature 0 | 2.5 | 0.1875 | Best overall |
| Feature 0 | 3.5 | 0.375 | |
| Feature 1 | 0.5 | 0.4375 |
Winner: Feature 0, threshold 2.5, weighted Gini =0.1875.
After this split:
- Right (x>2.5): all class 1 → pure leaf, predict 1
- Left (x≤2.5): still mixed → recurse and find the next best split
Common mistake
Comparing only one feature or one threshold. A tree must evaluate all features and all midpoints at each node—otherwise it can miss a much better split.
Key takeaway
The best split is the (feature, threshold) pair with the lowest weighted Gini. Trees repeat this search at every impure node until stopping conditions apply.
Use the Best Split Finder below to see every candidate ranked on the practice dataset.
Interactive
Best Split Finder
Compare every candidate split and see which threshold gives the lowest weighted Gini.
Best split
feature0 ≤ 2.5
Weighted Gini: 0.188
| Feature | Threshold | Left y values | Right y values | Gini(left) | Gini(right) | Weighted Gini |
|---|---|---|---|---|---|---|
| feature0 | 1.5 | [0, 0] | [0, 1, 1, 1, 1, 1] | 0.000 | 0.278 | 0.208 |
| feature0 | 2.5 | [0, 0, 0, 1] | [1, 1, 1, 1] | 0.375 | 0.000 | 0.188 ★ |
| feature0 | 3.5 | [0, 0, 1, 0, 1, 1] | [1, 1] | 0.500 | 0.000 | 0.375 |
| feature1 | 0.5 | [0, 0, 1, 1] | [0, 1, 1, 1] | 0.500 | 0.375 | 0.438 |
The best split has the smallest weighted Gini. Ties are broken by lower feature index (feature0 before feature1).
Practice
Try It Yourself
Open the practice lab to complete the starter code in the notebook.
Knowledge Check
Quick Quiz
The best split is the one with:
Summary
Key Takeaways
- The root split compares every feature and threshold candidate.
- The winning root split has the lowest weighted Gini impurity.
- A pure child branch can become a leaf immediately.