Skip to content
mlmentorship

Decision trees

Compute weighted split improvement, trace a root-to-leaf region, and test larger leaves, regression targets, and a greedy XOR failure.

Published · 6 min read ·Core ·Foundation
Reading depth

Summary

A decision tree predicts a constant value within each terminal feature region. Training chooses threshold splits greedily, using a stated criterion and stopping rules.

Task: the diagram has four circles, class zero, and four triangles, class one. Candidate root puts three circles and one triangle left; one circle and three triangles go right. Calculate its Gini reduction and predict a new point after the right-only child split .

The drawn split is a candidate, not a proven best threshold among unenumerated alternatives.

The algorithm (CART, Breiman et al., 1984)

  1. Enumerate allowed feature thresholds, usually midpoints between distinct ordered numeric values.
  2. Route left and right; reject candidates violating leaf constraints.
  3. Choose maximum sample-weighted impurity reduction, then recurse under the stopping rules.

This local choice need not produce the globally best tree.

Learning objective: map each root-to-leaf rule path to one axis-aligned region of feature space and its constant leaf prediction.

Rules become regions

The second split affects only the root's right-hand region

The second split affects only one root branchThe root sends every x<=0 point to A. Splitting y on the right branch changes only the x>0 region.The second split exists only insidethe right root branchACBRoot cut x=0. Right branch alonesplits at y=1.Every left-region point still belongsto A.
Derivation
A decision tree and its matching feature-space partition The upper plot contains four circle samples and four triangle samples. A full-height vertical root split at feature one equal to four sends four points left and four right. Only the right region receives a horizontal child split at feature two equal to three. The matching tree below has a root test feature one less than or equal to four. Its yes branch ends at a leaf with triangle probability one quarter. Its no branch tests feature two less than or equal to three, producing a pure triangle leaf below and a pure circle leaf above. A highlighted new point follows the no then yes path to the triangle leaf. feature 1 feature 2 root: x1 ≤ 4 child: x2 ≤ 3 new point 8 TRAINING POINTS: ○ CLASS 0, △ CLASS 1 THE SAME PARTITION, WRITTEN AS RULES x1 ≤ 4? yes no leaf L P(△) = 1/4 x2 ≤ 3? yes no leaf R1: P(△)=1 R2: P(△)=0
the solid root split routes every point. The dashed child test cuts only the right region. Intersecting the path's predicates gives its leaf region and constant empirical class fraction. The highlighted point follows “no, then yes” to R1. Sources: scikit-learn's formulation and The Elements of Statistical Learning.
Check: Why is the second split applied only on the right side of the root boundary?
Read it this way: The root sends every x<=0 point to A. Splitting y on the right branch changes only the x>0 region.
Does changing y above one move any x<=0 point out of A?

Split criteria

For class proportions , Gini impurity is . Use

StateCalculationGini
Parent
Each root child
Weighted root children

Root improvement is . The right child separates three triangles from one circle, leaving total weighted impurity . Point reaches that pure-triangle R1 leaf, with empirical triangle fraction .

Sample weights matter: a separate pure child of size three and impurity- child of size five give weighted impurity . An unweighted mean gives , incorrectly treating unequal child sizes equally.

Entropy gives entropy information gain, not the same numerical quantity as Gini reduction. For regression, a leaf mean minimizes its summed squared error.

Stopping and pruning

New task: require at least four samples per leaf. The 4/4 root remains legal; its proposed 3/1 right split does not. Check: now receives the unsplit right leaf’s triangle fraction , not . Use when: tiny leaves provide insufficient support or excessive variance.

New task: predict numeric targets with , , and threshold . Replace class fractions and Gini with means and squared residuals. Check: the unsplit mean has SSE ; leaf means and give SSE zero. Use when: the output is a continuous response.

Depth, minimum leaf size, purity, and improvement limits stop growth. Cost-complexity pruning compares subtrees using ; select using validation, not test outcomes.

Failure: either first axis split on four XOR corners has zero gain, although a depth-two tree separates them. Stopping on nonpositive immediate gain can miss that interaction.

Reconstruct: at exactly, does the right child inspect ?

Answer

No. The rule routes left; a child test applies only to the region reaching it.

Strengths and weaknesses

Paths provide explicit rules and can represent interactions through successive splits. Strictly increasing numeric transformations preserve candidate partitions when ordering and implementation arithmetic are preserved. Rotated boundaries may require many axis-aligned regions; feature engineering or oblique tests changes that representation. Small data changes can change selected splits. Neither a single tree nor an ensemble has a universal production ranking.

Categorical features

One-hot encoding and native categorical splitting define different candidate partitions and costs. Arbitrary integer codes impose an ordering that may not match category meaning. Target-based category statistics require leakage controls. Library algorithms, including CatBoost’s ordered statistics, are not interchangeable with simply sorting all categories by target mean.

Common pitfalls

Missing-value routing needs an explicit supported strategy: imputation, learned default directions, or surrogate splits, depending on implementation. Do not assume every tree accepts missing or categorical values. Empirical leaf fractions are not guaranteed calibrated probabilities for new populations. Feature importance can reflect split-selection biases; evaluate stability and held-out perturbations before interpreting it.