Ensemble learning by combining many simple trees into one powerful model.
A decision tree is a flowchart: start at the root, ask a yes/no question about a feature, follow a branch, repeat until reaching a leaf (prediction).
Example: Predict if loan will default. Split on income: "income > $50k?" If yes, check credit score. If no, check employment status. Leaf: "approve" or "deny".
Trees are interpretable (you can trace the logic) but prone to overfitting (too many splits memorize training data noise).
Build many trees, each slightly different (random subsets of data, random feature splits). Prediction: average (regression) or majority vote (classification) across all trees.
Why it works: individual trees are imperfect, but averaging independent imperfect models reduces variance and overfitting.
1. Bootstrapping (bagging): For each tree, sample training data with replacement. Each tree sees a slightly different dataset.
2. Random feature selection: At each split in each tree, choose best split from a random subset of features (not all features). Forces diversity; prevents one dominant feature from controlling all trees.
3. Shallow trees: Usually grow trees to full depth but stop before massive overfitting. Combine many weak learners.
4. Out-of-bag (OOB) error: Data not selected for a tree's bootstrap sample can estimate generalization error without a separate test set.
Extremely Randomized Trees (Extra Trees): Use random split thresholds instead of optimized splits. Faster training, can reduce overfitting more.
Gradient Boosting (XGBoost, LightGBM): Build trees sequentially, each correcting errors of the previous. Often outperforms random forests but slower to train and more tuning required.
Random Forests for regression: Predict continuous values instead of classes. Average tree predictions instead of voting.