What a split is chosen to reduce
A tree grows by asking, at every node, which single question about one feature best separates the labels.
- : the fraction of the samples at this node that carry class .
- : the number of classes.
This is Gini impurity: 0 when a node holds one class only, and when the classes are spread evenly.
Entropy measures the same thing on a different scale, and in practice the two pick almost the same splits.
The gain a split has to earn
- : the impurity measure, Gini or entropy.
- : how many samples go left and right.
- : how many arrived at this node.
The children are weighted by size, so a split that peels off three clean samples out of a thousand scores almost nothing.
The split with the largest is taken, and the process repeats on each child.
One tree, in order
- Start with every training sample at the root.
- For each feature, try every threshold that separates two observed values.
- Score each candidate split by its weighted impurity drop.
- Keep the best one and send the samples left or right.
- Repeat on each child until a stopping rule fires.
- Label each leaf with the majority class of the samples that reached it.
Regression trees change only the impurity
Variance replaces Gini, the leaf predicts the mean of its samples instead of a majority, and every other step is identical.
Why an unstopped tree is useless
Grown without limit, a tree keeps splitting until every leaf holds one sample, which fits the training set perfectly and generalises to nothing.
- : the tree's error.
- : the number of leaves.
- : the price charged per leaf.
Cost-complexity pruning grows the tree fully and then removes the branches that do not pay for themselves at a given , chosen by cross-validation.
The cheaper controls are a maximum depth, a minimum number of samples per leaf, and a minimum gain, all of which stop the tree before it memorises.
The two properties that decide when to use one
A tree is invariant to monotone transforms of a feature, so scaling and log transforms change nothing about which splits it picks.
Its boundaries are axis-aligned rectangles, so a diagonal boundary has to be approximated by a staircase and a single rotation of the data can ruin it.