MACHINE LEARNING / 4. RANDOM FOREST
Random Forest
Bagging + feature randomness = robust ensemble
EXPLANATION
Random Forest is an ensemble of decision trees trained on random subsets of data and features. Two sources of randomness: 1. Bootstrap sampling (Bagging) → each tree trained on ~63% of data, sampled with replacement 2. Feature subsampling → at each split, only √n_features are considered Why this works — bias-variance tradeoff: • Single deep tree: low bias, high variance (overfits) • Average of many uncorrelated trees: low bias, lower variance Because trees are decorrelated (different data + different features), their errors cancel out when averaged. This is the core insight. Out-of-bag (OOB) score: samples not used in a tree's bootstrap sample can be used as validation — you get a free cross-validation estimate. Random Forest is often the best "first serious model" to try on tabular data before gradient boosting.
DATA FLOW
Training data (N samples)
↓ Bootstrap sampling × T trees
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Tree 1 │ │ Tree 2 │ │ Tree T │
│ subset │ │ subset │ │ subset │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
At each split: only √p features considered (decorrelation)
│ │ │
└────────────┼────────────┘
↓
Majority vote (classification)
Mean prediction (regression)CODE