What is a Random Forest and how does it make a prediction?
Last updated
A Random Forest is an ensemble of decision trees. Each tree is trained on a bootstrap sample and considers random feature subsets at each split. It predicts by combining the trees: majority vote (or averaged probabilities) for classification, and the mean for regression.
Training: two sources of randomness:
Row sampling: each tree is fit on a bootstrap sample (n rows drawn with replacement).
Feature sampling: each split only searches a random subset of
max_featuresfeatures.Trees are usually grown deep (low bias, high variance) and are not pruned.
Prediction:
Each tree routes the sample to a leaf and outputs that leaf's class distribution or mean value.
Classification uses a majority vote.
scikit-learninstead averagespredict_probaacross trees and takes the argmax.Regression averages the trees' numeric predictions.
Why it works:
Averaging many diverse, weakly correlated trees cancels out their individual errors.
The result has much lower variance than a single tree, at roughly the same bias.
Practical perks:
Little tuning is needed.
Out-of-bag error gives a free validation estimate.
Feature importances come built in.
Trees are independent, so training parallelizes easily.