Random Forest
Let many small trees vote for a steadier answer.
Drag the new seed, or tap anywhere on the graph. Every tree below votes, and the forest answers with the most votes.
- sprouts
- stays dry
- new seed: drag it, or tap the graph
- Thow many trees vote
T = 9 trees: 4 dry, 5 sprout → sprouts (56% of the votes)
Tree 1 drew 30 seeds at random, with repeats: it saw 21 different seeds and never saw 9. It says sprout.
| 1 | 21 | 9 | 3 | sprout |
| 2 | 18 | 12 | 4 | sprout |
| 3 | 19 | 11 | 4 | dry |
| 4 | 15 | 15 | 4 | dry |
| 5 | 19 | 11 | 2 | dry |
| 6 | 18 | 12 | 4 | sprout |
| 7 | 19 | 11 | 3 | sprout |
| 8 | 19 | 11 | 4 | dry |
| 9 | 19 | 11 | 2 | sprout |
Try it in Python
The same 30 seeds, trees and new seed as the Lab, in Python. Plain Python uses the Lab's own random numbers, so it grows the Lab's exact trees; scikit-learn makes its own random choices.
What you are looking at
Each shape is a seed in a tray. Across the graph is how warm its soil was; up the graph is how much water it got each day. Circles sprouted and triangles stayed dry. Seeds sprout when warmth and water together are enough, so the border between them runs on a slant.
The diamond is a new seed. Its colour is the forest's answer, and the shading shows the answer everywhere else: stronger where more trees agree. Below the graph, every tree is drawn as a small map. The numbers are made up, and Refresh Data shows another tray of 30 seeds.
What each symbol means
- q
- The new seed, the one we want an answer for.
- hₜ(q)
- The answer of tree number t.
- T
- How many trees vote. It is always odd, so the vote never ties.
- n
- How many seeds there are to learn from.
- ŷ
- The forest's answer: sprouts or stays dry.
How a forest is grown
A random forest is many small decision trees that vote. If every tree learned from the same seeds in the same way, they would all be the same tree, and the vote would add nothing. So each tree gets two kinds of chance:
- Its own sample. Each tree draws n seeds at random, putting each one back after drawing it. Some seeds come twice or more, and some not at all. Pick a tree to see its sample on the big graph.
- Its own questions. At each question, the tree may only look at one feature, picked at random: temperature or water. It then finds the best threshold on that feature.
- A vote. For a new seed, each tree gives its answer, and the most common answer wins.
Why many trees beat one
One tree can only cut the chart with straight lines across and up, so a slanted border becomes a rough staircase. Each tree's staircase is different, and its mistakes are in different places. When they vote, the mistakes tend to cancel out, and the forest's border follows the slant more closely than any single tree.
Odd seeds near the border fool some trees but not others: a tree that never drew the odd seed does not bend around it. That is why a forest is steadier than one deep tree.
Choosing T, and an honest score
More trees make the vote steadier, and they never make the forest worse at learning; they only cost time. After a few dozen trees the answer hardly changes.
Every tree leaves out about a third of the seeds, which gives a free test. The score Right on unseen seeds asks, for each seed, only the trees that did not draw it. This is called the out-of-bag score, and it tells you how the forest does on seeds it has not learned from.
The model in short
- Sample: each tree draws its own seeds, with repeats.
- Grow: each question looks at one feature picked at random.
- Vote: the forest answers with the most common answer.
- Check: test each seed on the trees that never saw it.