Separating by asking questions 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
The red circles are days when the ice cream sold out, the blue squares days when it did not. A decision tree starts with a single question: is a feature below a threshold? Then it asks each part new questions.
First question: temperature 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
Every threshold was tried. The best first question: is the temperature below 21.50 degrees? The thick line is this split. Its quality is measured with Gini impurity; before the split Gini is 0.50, and this question lowers it the most.
Deeper questions 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
Each part is split the same way until it is pure or reaches the depth limit of 2 questions. The dashed lines are these 1 extra splits. The tree has 3 leaves.
Decision regions 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
Each leaf is a rectangular region and gives the majority class of its days. A tree's boundaries are always parallel to the axes, in steps. A share of 0.94 of the training days is classified correctly.
New day: not sold out 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
26 degrees, 6 hours of sun. With its answers to the questions the day goes down to a leaf; most days in that leaf did not sell out. The decision is not sold out.
Depth and memorising 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
As depth grows, the tree can split until every training day is classified right, yet it gets new days wrong: overfitting. Change the depth between 1 and 4 in the Try tab and watch the regions break up.
Why it matters 8 12 16 20 24 28 32 36 0 2 4 6 8 10 12 temperature, degrees sunny hours
A decision tree can be read: every prediction is explained by a few yes or no questions. Since a single tree is unstable, many trees are used together in practice; random forests and gradient boosting are the next topic.