This Machine Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Machine Learning
Decision Trees
Decision trees split feature space into simple regions; the split rule is local impurity reduction, not a guarantee of robust understanding.
Concept Structure
Decision Trees
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
1 prerequisite listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
A decision tree learns by asking a sequence of small questions:
If I cut the data here, do the two child regions become easier to label?
Each internal node is a test such as . Each leaf is a region of feature space. For classification, the leaf usually predicts the majority class among the training examples that landed there.
That makes trees feel wonderfully concrete. You can trace a prediction through visible rules. But this is also the trap: readable rules are not automatically reliable rules. The split is chosen by a local score, not by global understanding. A tiny change near an early split can change the first question, and then every downstream branch sees a different training subset.
So the core mechanism is:
- measure impurity in the parent node,
- test candidate splits,
- compute the weighted impurity of the children,
- pick the split with the largest reduction,
- repeat until a stopping or pruning rule says enough.
The first split matters because it reshapes the rest of the problem.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let a node contain a set of training indices . For a -class classification problem, define
the fraction of examples in region whose class is .
One common impurity score is the Gini impurity:
A pure node has all examples in one class, so one is and . A mixed node has larger impurity.
Another common score is entropy:
with the convention that .
Now consider a candidate split . It sends the parent region into two children:
For an impurity function , the weighted child impurity is
The split gain is
A greedy tree chooses
After the split, a classification leaf predicts
This is precise but local. The optimization over full tree structures is combinatorial, so practical trees use greedy recursive splitting plus controls such as maximum depth, minimum leaf size, or cost-complexity pruning. Interpretability comes from the rule trace; reliability still has to be checked with held-out evaluation, cross-validation, and sensitivity to data changes.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import math
points = [
(0.14, 0.78, 1), (0.18, 0.30, 1), (0.25, 0.62, 1),
(0.36, 0.21, 1), (0.42, 0.50, 0), (0.52, 0.82, 1),
(0.63, 0.26, 0), (0.70, 0.60, 1), (0.82, 0.74, 0),
(0.88, 0.38, 0), (0.48, 0.46, 0), (0.56, 0.58, 0),
]
splits = [("x <= 0.47", 0, 0.47), ("y <= 0.55", 1, 0.55), ("x <= 0.70", 0, 0.70)]
def impurity(labels, criterion="gini"):
n = len(labels)
ps = [labels.count(k) / n for k in set(labels)]
if criterion == "entropy":
return -sum(p * math.log2(p) for p in ps)
return 1 - sum(p * p for p in ps)
def gain(split, criterion="gini"):
_, axis, threshold = split
left = [label for *xy, label in points if xy[axis] <= threshold]
right = [label for *xy, label in points if xy[axis] > threshold]
parent = impurity([label for *_, label in points], criterion)
weighted = (len(left) / len(points)) * impurity(left, criterion)
weighted += (len(right) / len(points)) * impurity(right, criterion)
return parent - weighted, left, right
for split in splits:
score, left, right = gain(split)
print(split[0], round(score, 3), "left", left, "right", right)
The code is the root-split ledger in miniature: compute parent impurity, split the rows, weight the child impurities, and choose the largest reduction.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the lab as a split-selection microscope. First choose the criterion and dataset case. Then predict which candidate root split wins before revealing the impurity ledger. In the perturbed case, one ambiguous label changes the root split, which is the point: a tree can be easy to read and still sensitive.
Live Concept Demo
Explore Decision Trees
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Decision Trees should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Decision trees split feature space into simple regions; the split rule is local impurity reduction, not a guarantee of robust understanding.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Decision Trees should make visible.
Visual Inquiry
Make the image answer a mathematical question
Decision trees split feature space into simple regions; the split rule is local impurity reduction, not a guarantee of robust understanding.
Which visible object should carry the first intuition?
Pick the cue that should make Decision Trees easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Supports decision trees as nonlinear classifiers, entropy and Gini splitting losses, and the warning that trees are high-variance and prone to overfitting.
Open sourceSupports recursive binary splitting, partitioning predictor space into regions, classification-tree majority-class prediction, Gini/entropy node purity, cost-complexity pruning, and tree instability.
Open sourceSupports CART-style recursive partitions, node impurity measures, Gini and cross-entropy/deviance, greedy region search, pruning, and the bridge from trees to ensembles.
Open sourceClaim Review
Decision trees split feature space into simple regions; the split rule is local impurity reduction, not a guarantee of robust understanding.
Claims without a substantive review badge still need exact source-support review.
cs229-2021-decision-trees, james-2023-islr-tree-based-methods, hastie-2009-esl-trees
Use equations, runnable code, and demos to check whether the source support is operational.
The sources support the split-by-impurity framing, region/leaf prediction interpretation, Gini and entropy formulas, greedy recursive construction, pruning/regularization need, and the caveat that single trees can be unstable.
Sources: CS229 Decision Trees, An Introduction to Statistical Learning, Chapter 8, The Elements of Statistical Learning, Chapter 9The interactive lab is a one-level classification split witness. It does not implement a full CART search over all thresholds, cost-complexity pruning, categorical/surrogate splits, missing-value handling, oblique trees, statistical consistency, or ensemble methods.A bounded review summary is present; still check caveats and exact reference scope.Checked Stanford CS229 decision-tree notes, ISLR Chapter 8, and ESL Chapters 9-10 for recursive binary splitting, partition regions, majority-class leaves, Gini and entropy/cross-entropy impurity criteria, greedy approximate optimization, pruning/regularization, high variance, and ensemble motivation. GPT Pro critique remains pending because the browser lane at 127.0.0.1:51672 was unavailable.
Reviewer: codex-local-source-review; reviewed 2026-07-02Source support candidates
course-notes 2021CS229 Decision TreesSupports decision trees as nonlinear classifiers, entropy and Gini splitting losses, and the warning that trees are high-variance and prone to overfitting.
book 2023An Introduction to Statistical Learning, Chapter 8Supports recursive binary splitting, partitioning predictor space into regions, classification-tree majority-class prediction, Gini/entropy node purity, cost-complexity pruning, and tree instability.
book 2009The Elements of Statistical Learning, Chapter 9Supports CART-style recursive partitions, node impurity measures, Gini and cross-entropy/deviance, greedy region search, pruning, and the bridge from trees to ensembles.
Practice Loop
Try the idea before it explains itself
Decision trees split feature space into simple regions; the split rule is local impurity reduction, not a guarantee of robust understanding.
Before touching the demo, predict one visible change that should happen in Decision Trees.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Decision Trees
What is the smallest example that makes Decision Trees click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Decision Trees Selected item key: recorded for copy. Context: Machine Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Decision Trees click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/machine-learning/decision-trees
concept:machine-learning/decision-trees