Decision Tree
Decision Tree — Split the data with a sequence of yes/no questions.
A decision tree classifies by asking a series of simple yes/no questions, splitting the data at each step. Follow the branches down to a leaf and you get your prediction.
- Class 0
- Class 1
- Selected region
Tree controls
The idea in plain words
A decision tree classifies by asking a sequence of yes/no questions, each one a threshold on a single feature. Every split appears twice at once: as a branch in the tree and as a straight cut in the feature space. Follow the branches to a leaf and you have your prediction.
Each split is chosen to make the resulting groups as pure as possible. Let the tree grow without limit and it will carve a separate box around every point — perfect on training data, hopeless on anything new. That fragility is exactly what forests fix.
Now, the math
Splits are chosen to reduce Gini impurity, a measure of class mixing:
- the fraction of a node’s points belonging to class k.
- a pure node — every point is the same class.
▸ Show the derivation
At each node the tree tries every threshold on every feature and picks the split that most reduces the weighted Gini of the children. Because splits are axis-aligned, boundaries are always staircases of horizontal and vertical cuts — never diagonal.
Trace it by hand
A node holds 8 points, 4 of class A and 4 of class B. Candidate split: x at most 2.5, which sends 3 A and 1 B left, and 1 A and 3 B right. All Gini values computed by the tree core.
Gini of the parent node
0.5 is the worst possible mixing for two classes.
Gini of the left child (3 A, 1 B)
Gini of the right child (1 A, 3 B)
Weighted average and gain
The tree tries every threshold on every feature and keeps the split with the largest gain.
What just happened: One vertical cut turned a 50-50 node of Gini 0.5 into two 75-25 children of Gini 0.375 — a gain of 0.125. Growing a tree is just repeating this arithmetic greedily until the leaves are pure.
Now Break It
Try this: Unlimited depth grows a leaf for every point — perfect on train data, jagged and overfit everywhere else.
Control: Max depth slider (set to maximum)
What happens: Overfitting! With unlimited depth the tree isolates every single point — pure memorization.
Where decision tree is used
A decision tree classifies by asking a sequence of yes-or-no questions about the features, following the answers down branches until it reaches a leaf that assigns a label. This mirrors how humans reason through checklists, which is why trees are prized in settings that demand transparency. Banks use them for loan approval rules, doctors use them for triage and diagnostic pathways, and businesses use them to segment customers or to encode operational policies that staff can follow by hand. Trees handle mixed numeric and categorical data, need little preprocessing, and require no feature scaling. Just as importantly, a trained tree can be printed and read directly, so a stakeholder can trace exactly why a particular decision was made, which is invaluable when decisions must be justified or audited.
The main pitfall is that a single unconstrained decision tree overfits easily, growing until it memorizes the training data with a leaf for nearly every point. Such a tree looks flawless on training data yet generalizes poorly, which is why pruning, limiting depth, or requiring a minimum number of samples per leaf are essential. Another misconception is that trees are stable; in reality they are high-variance, and a small change in the data can produce a very different tree. This instability is exactly what ensemble methods like random forests and gradient boosting exploit and correct by averaging many trees. Finally, standard trees split on one feature at a time, so they struggle with relationships that depend on features in combination.
Frequently asked questions
How does a decision tree decide where to split?
What is pruning and why does it matter?
Do decision trees need feature scaling?
Why are decision trees considered unstable?
How are decision trees different from random forests?
Written & reviewed by the ML Visualization team · Last updated .