labs / supervised
Decision Tree Splits
How a tree carves up a 2D dataset by repeatedly choosing the single best cut.
A decision tree classifies points by asking a series of yes/no questions, each one a straight cut along a single axis: "is x greater than 5.2?" The tree is built greedily — at every step, it picks whichever single cut best separates the two classes, then repeats inside each half.
Measuring "best"
"Best separates the classes" is measured with Gini impurity: how often you'd be wrong if you guessed a point's class at random, based on the mix already in that group.
gini(group) = 1 − p₀² − p₁²
where p₀ and p₁ are the fractions of each class in the group. A group with only one class has gini = 0 (perfectly pure); an even 50/50 mix has the highest possible impurity.
Choosing a split
For every candidate threshold on x and on y, the tree checks how impure the two resulting groups would be, weighted by size, and keeps whichever threshold minimizes that weighted impurity:
weighted_gini = (n_left/n)·gini(left) + (n_right/n)·gini(right)
That becomes one line in the picture. The tree then repeats the same search separately inside the left and right groups, up to a maximum depth — which is why later splits are shorter: they only apply within the region the earlier splits carved out.
Press play to reveal each split in the order it was chosen (root first), or step through one at a time.