Decision Tree
A flowchart of yes/no questions that ends in a prediction.
The idea
At each node the tree picks the feature and threshold that best separates the classes, measured by impurity such as Gini or entropy. It splits the data, then repeats on each side until the groups are pure or a depth limit is reached. The result is easy to read, but a deep tree memorises the training data.
Gini = 1 − Σ pₖ²
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- class 0
- class 1
All the data starts in one box. The tree will ask yes/no questions to separate the classes.
- impurity:
- 0.5
Every cut is axis-aligned, so each region is a rectangle. Deeper trees carve finer boxes and can overfit.
Step by step
- 1Start with all the data at the root.
- 2Try every feature and threshold; pick the split with the lowest impurity.
- 3Split the data into two groups.
- 4Repeat on each group until a stopping rule is met.
- 5To predict, follow the questions down to a leaf.
Where it is used
Interpretable rules for credit, medicine and customer segmentation.
Watch out for
Overfits easily and changes a lot with small changes in data. Pruning and depth limits help.