A random forest combines predictions from multiple decision trees. Each tree is trained on a random subset of the data, and the trees vote on a classification prediction. Combining learners can help reduce overfitting compared with relying on one model. section 12.1 section 12.2
A simple way to picture the process:
- Choose random subsets of the dataset; some examples may appear in several subsets, others in none. section 12.2
- Train a decision tree on each subset. section 12.2
- Combine the trees’ predictions by voting. section 12.2
Classifying email
For a small spam-and-ham dataset, the features are counts of “lottery” and “sale” in each email. A single deep tree fits the training data perfectly but overfits outliers; a forest combines trees to classify the emails. section 12.2
Figure 12.6 The way to obtain the predictions of the random forest is by combining the predictions of the three weak learners. On the top, we can see the three boundaries of the decision trees from figure 12.5. On the bottom, we can see how the three decision trees vote to obtain the boundary of the corresponding random forest.
Compare the individual tree boundaries with the forest’s combined voting boundary. section 12.2
For hands-on use, Scikit-Learn’s RandomForestClassifier fits a forest. Random forests also work for regression; the worked example focuses on classification. section 12.2










