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:

  1. For each feature, generate all midpoint thresholds.
  2. For each (feature, threshold) pair, split the data into left and right groups.
  3. Compute weighted Gini for that split.
  4. 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=nleftnGini(left)+nrightnGini(right)\text{Weighted Gini} = \frac{n_{\text{left}}}{n} \cdot \text{Gini}(\text{left}) + \frac{n_{\text{right}}}{n} \cdot \text{Gini}(\text{right})

The best split minimizes this score:

Best split=argminfeature,t  Weighted Gini\text{Best split} = \arg\min_{\text{feature},\, t} \;\text{Weighted Gini}

If 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:

FeatureThresholdWeighted GiniNotes
Feature 01.50.208
Feature 02.50.1875Best overall
Feature 03.50.375
Feature 10.50.4375

Winner: Feature 0, threshold 2.52.5, weighted Gini =0.1875= 0.1875.

After this split:

  • Right (x>2.5x > 2.5): all class 1 → pure leaf, predict 1
  • Left (x2.5x \leq 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

feature02.5

Weighted Gini: 0.188

FeatureThresholdLeft y valuesRight y valuesGini(left)Gini(right)Weighted Gini
feature01.5[0, 0][0, 1, 1, 1, 1, 1]0.0000.2780.208
feature02.5[0, 0, 0, 1][1, 1, 1, 1]0.3750.0000.188
feature03.5[0, 0, 1, 0, 1, 1][1, 1]0.5000.0000.375
feature10.5[0, 0, 1, 1][0, 1, 1, 1]0.5000.3750.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.