Sitemap
Affan Ahmed

Affan Ahmed

I am a Data Science and AI professional, I like to share some of my learnings here.

3 min readSep 8, 2026

--

๐—˜๐—ป๐˜€๐—ฒ๐—บ๐—ฏ๐—น๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด: ๐—ช๐—ต๐˜† ๐—–๐—ผ๐—บ๐—ฏ๐—ถ๐—ป๐—ถ๐—ป๐—ด ๐— ๐—ผ๐—ฑ๐—ฒ๐—น๐˜€ ๐—–๐—ฎ๐—ป ๐—•๐—ฒ๐—ฎ๐˜ ๐—ฎ ๐—ฆ๐—ถ๐—ป๐—ด๐—น๐—ฒ ๐— ๐—ผ๐—ฑ๐—ฒ๐—น

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.

--

--

Affan Ahmed
Affan Ahmed

Written by Affan Ahmed

I am a Data Science and AI professional, I like to share some of my learnings here.