Classical machine learningML 07
Random Forests
A single deep decision tree fits its training data closely but changes a lot if the data change a little. A random forest grows many trees, each on a different random resample of the data and each limited to a random choice of features at every split, and averages their predictions: each tree gives the share of each class in the leaf a point falls into, and the class with the highest average wins. This is “soft voting”, which scikit-learn uses; Breiman’s original forests took a majority vote of the trees’ classes instead, and the two rules can disagree near the boundary. The individual trees disagree in their details, but their mistakes partly cancel out, so the forest is far steadier than any one of them. Random forests work well with little tuning, which has made them one of the most widely used methods for tabular data. Hover over the plot to see the trees vote, or over a tree below to see it on its own. The data are fictional and simplified.
The first 12 trees each drawn with the points in its bootstrap sample · hover one to show it on the main plot, with the points it never saw faded
Accuracy as trees are added vertical line: the number of trees in the vote
shading: the class the forest predicts, stronger where the trees agree more · bars: the average of the trees' class probabilities, which decides; numbers: how many trees vote for each class · hollow: test points
Two kinds of randomness
Each tree is grown on a bootstrap sample: as many points as the training set, drawn with replacement, so some points appear several times and about a third (1/e ≈ 37%) are left out. This is bagging (bootstrap aggregating; Breiman, 1996). On its own it still gives similar trees, because they all choose the same strong first splits, so a random forest also restricts which features each tree may use. Ho (1995) gave each tree its own random subset of features; Amit and Geman (1997) drew a new random subset at every split, and Breiman (2001) adopted that per-split version, which is the one used here. With two features that means one, picked at random, and the trees become genuinely different. Averaging many trees that are each accurate but err in different places reduces the variance without adding much bias.
Out-of-bag accuracy
Because every tree misses about a third of the points, each point can be classified by just the trees that never saw it. The resulting out-of-bag accuracy behaves like accuracy on a test set, without setting any data aside. In the chart it rises quickly over the first few trees and then levels off: adding more trees never makes a forest overfit, it only stops helping. That is not the same as saying forests cannot overfit: deep trees still fit noise, and the forest inherits some of it. The cost is interpretability: a forest of a hundred trees can no longer be read like a single flowchart.
References
- Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5–32. doi.org/10.1023/A:1010933404324
- Breiman, L. (1996). Bagging predictors. Machine Learning, 24(2), 123–140. doi.org/10.1007/BF00058655
- Amit, Y., & Geman, D. (1997). Shape quantization and recognition with randomized trees. Neural Computation, 9(7), 1545–1588. doi.org/10.1162/neco.1997.9.7.1545
- Ho, T. K. (1995). Random decision forests. In Proceedings of the 3rd International Conference on Document Analysis and Recognition, Montreal (Vol. 1, pp. 278–282). IEEE. doi.org/10.1109/ICDAR.1995.598994
- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.), chapters 8.7 and 15. Springer. doi.org/10.1007/978-0-387-84858-7