๐๐ป๐๐ฒ๐บ๐ฏ๐น๐ฒ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด: ๐ช๐ต๐ ๐๐ผ๐บ๐ฏ๐ถ๐ป๐ถ๐ป๐ด ๐ ๐ผ๐ฑ๐ฒ๐น๐ ๐๐ฎ๐ป ๐๐ฒ๐ฎ๐ ๐ฎ ๐ฆ๐ถ๐ป๐ด๐น๐ฒ ๐ ๐ผ๐ฑ๐ฒ๐น
Why rely on a single model when you can combine several models and potentially get more accurate, stable, and robust predictions?
That's the core idea behind ensemble learning.
Instead of relying on one algorithm's predictions, we train multiple models and combine their outputs into a final prediction.
๐ ๐ฆ๐ถ๐บ๐ฝ๐น๐ฒ ๐๐ ๐ฎ๐บ๐ฝ๐น๐ฒ
Suppose we're building a classification system and train three different models:
๐น Logistic Regression โ captures linear relationships and is highly interpretable.
๐น Random Forest โ captures non-linear patterns and interactions using many decision trees.
๐น XGBoost โ builds trees sequentially, focusing on correcting the errors of previous trees.
Each model has different strengths and weaknesses.
One model might get a particular observation wrong while another gets it right. If their errors aren't perfectly correlated, combining their predictions can produce a stronger overall model.
๐๐ผ๐ ๐๐ฎ๐ป ๐ช๐ฒ ๐๐ผ๐บ๐ฏ๐ถ๐ป๐ฒ ๐ง๐ต๐ฒ๐บ?
๐ญ. ๐๐ฎ๐ฟ๐ฑ ๐ฉ๐ผ๐๐ถ๐ป๐ด
Each model predicts a class, and the majority wins.
For three models:
Model A โ Class 1
Model B โ Class 1
Model C โ Class 0
Final prediction โ Class 1
Simple, but it ignores how confident each model is.
๐ฎ. ๐ฆ๐ผ๐ณ๐ ๐ฉ๐ผ๐๐ถ๐ป๐ด
Instead of using class labels, combine predicted probabilities.
For example:
Logistic Regression โ 0.62
Random Forest โ 0.71
XGBoost โ 0.68
Average:
(0.62 + 0.71 + 0.68) / 3 = 0.67
With a 0.5 threshold โ Class 1
Unlike hard voting, soft voting preserves the models' confidence information.
๐ก ๐ก๐ผ๐๐ฒ: In the case of regression problems, there are no classes or probabilities to vote on. Instead, the ensemble simply takes the mathematical average of the numerical predictions from all models.
๐ฏ. ๐ช๐ฒ๐ถ๐ด๐ต๐๐ฒ๐ฑ ๐๐๐ฒ๐ฟ๐ฎ๐ด๐ถ๐ป๐ด
Not every model needs to have equal influence.
Get Affan Ahmedโs stories inย yourย inbox
Join Medium for free to get updates fromย thisย writer.
If XGBoost consistently performs better on validation data, we could assign it a larger weight.
For example:
Logistic Regression (Weight: 0.2) โ 0.62
Random Forest (Weight: 0.3) โ 0.71
XGBoost (Weight: 0.5) โ 0.68
Calculation:
(0.2 ร 0.62) + (0.3 ร 0.71) + (0.5 ร 0.68) = 0.677
With a 0.5 threshold โ Class 1
The final prediction becomes a weighted combination of their outputs.
๐ฐ. ๐ฆ๐๐ฎ๐ฐ๐ธ๐ถ๐ป๐ด
Instead of manually deciding the weights, we can train another model to learn how to combine the base models.
The predictions from the first-layer models become inputs to a meta-model.
For example:
Logistic Regression + Random Forest + XGBoost โ Meta-model โ Final prediction
The meta-model learns which predictions to trust and how to combine them.
๐ฑ. ๐๐ฎ๐ด๐ด๐ถ๐ป๐ด & ๐๐ผ๐ผ๐๐๐ถ๐ป๐ด
Some ensemble methods are already ensembles themselves.
๐ณ Random Forest = Bagging + many decision trees
โก XGBoost = Gradient Boosting + many decision trees
So combining Random Forest, XGBoost, and Logistic Regression is effectively creating an ensemble containing different types of models โ including ensemble models themselves.
๐ช๐ต๐ ๐๐ผ ๐๐ป๐๐ฒ๐บ๐ฏ๐น๐ฒ๐ ๐ช๐ผ๐ฟ๐ธ?
The key is diversity.
If several models make exactly the same mistakes, combining them won't provide much benefit.
But if their errors are different, one model can compensate for another's weaknesses.
This can lead to:
โ
Better predictive performance
โ
Greater robustness
โ
More stable predictions
โ
Reduced variance โ particularly with techniques such as bagging
โ
Better handling of complex patterns when models capture complementary relationships
โ ๏ธ ๐ง๐ต๐ฒ ๐ง๐ฟ๐ฎ๐ฑ๐ฒ-๐ข๐ณ๐ณ
Ensembling isn't automatically better.
More models mean:
โ More computational cost
โ More complexity
โ More difficult interpretation
โ More complicated deployment and monitoring
And combining several highly correlated models that make similar mistakes may provide little or no improvement.
The real power of an ensemble comes from combining models that are both reasonably strong and sufficiently diverse.
๐ง๐ต๐ฒ ๐๐ถ๐ด ๐ฃ๐ถ๐ฐ๐๐๐ฟ๐ฒ
Ensemble learning isn't about finding one perfect model.
It's about recognizing that every model has blind spots โ and combining models in a way that prevents those blind spots from lining up.
One model gives you one perspective.
An ensemble gives you several perspectives โ and a way to combine them.





