Ensemble Learning and Random Forests
Ensemble methods combine predictions from multiple base models to build a stronger predictor with improved generalization.
Voting Classifiers
Ensemble models aggregate individual predictions using different consensus rules:
- Hard Voting: predicts the class that receives the absolute majority of votes from the base estimators.
- Soft Voting: averages the predicted class probabilities across all estimators, prioritizing confident predictions. This requires all estimators to support probability calculation.
Bagging and Pasting
Rather than using diverse algorithms, we can train multiple instances of the same base algorithm on different random subsets of the training set to construct homogeneous ensembles:
- Bagging (Bootstrap Aggregating): sampling is performed with replacement, allowing the same data point to be selected multiple times across different subsets.
- Pasting: sampling is performed without replacement, ensuring each subset contains unique data points.
Out-of-Bag (OOB) Evaluation
With bagging, statistical probability dictates that about 37% of the training instances are never sampled for any single estimator. These are known as Out-of-Bag (OOB) instances. Evaluating the ensemble’s performance on these OOB instances provides an unbiased validation score without requiring a separate validation dataset.
Random Forests
A Random Forest is an ensemble of decision trees trained via bagging. Tree splits are evaluated on random feature subsets to reduce estimator correlation and variance.
Example: Ensemble Voting Classifier
The following example demonstrates building a Voting Classifier:
Interactive Lab
Train individual estimators (Logistic Regression, Decision Tree) and combine them into a soft Voting Classifier ensemble to observe performance updates.
Exercise
Test your understanding of bootstrap aggregation: