Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 6

Ensemble Learning: Bagging & Boosting

Recommended resources

Welcome to our next lesson. In our previous sessions, we explored how a single decision tree is built, from understanding overfitting to using metrics like Gini Impurity and Entropy to make optimal splits. We saw that a single tree, while powerful, often struggles with the bias-variance trade-off—it can either be too simple (high bias) or too complex (high variance). This raises a powerful question: if one model is good, could a team of models be even better?

This lesson introduces the answer: Ensemble Learning. Your learning outcome is to define Ensemble Learning and explain the core ideas of Bagging and Boosting. This is a fundamental concept in modern machine learning, often summarized by the idea that the "wisdom of the crowd" can outperform any single expert. We will see how combining multiple simple models, like the decision trees we've studied, can lead to significantly more accurate and robust predictions.

1. What is Ensemble Learning?

At its core, ensemble learning is a strategy that combines multiple machine learning models to create a single, superior predictive model. The individual models in the ensemble are often called "weak learners" because on their own, they might not be very accurate. However, when their predictions are combined in a clever way, they form a "strong learner" that is much more powerful.

This approach is highly effective because different models may make different kinds of errors. By combining them, their individual errors can cancel each other out, leading to a more accurate and stable final prediction. This is directly related to the bias-variance trade-off we discussed earlier.

Let's ground this concept by reading a short overview.

Bagging, Boosting and Stacking: Ensemble Learning in ML ...

This article from Analytics Vidhya provides a clear definition of ensemble learning and explains its connection to the bias-variance trade-off.

First, read the brief definition of Ensemble learning. Then, scroll down to the section "How Ensemble Learning Works" and read the passages that define weak learners and explain how ensembles relate to the bias-variance trade-off.

As the article explains, some weak learners might have high variance (overfitting), meaning they are too sensitive to the training data. Others might have high bias (underfitting), meaning they are too simple to capture the underlying patterns. Ensemble methods are designed to specifically target one of these issues.

We will focus on the two most important and common ensemble strategies: Bagging and Boosting.

This diagram illustrates the three primary ensemble methods. We will focus on Bagging, with its parallel structure, and Boosting, with its sequential structure.

2. Bagging: Reducing Variance Through Parallel Learning

Bagging, which stands for Bootstrap Aggregating, is an ensemble technique designed primarily to reduce a model's variance. It's an intuitive approach based on the idea of averaging out noise.

The process is best understood as a three-step workflow:

  1. Bootstrap: Create many new, slightly different training datasets from the original data. This is done by sampling with replacement. Imagine putting all your data points into a bag, drawing one out, noting it down for your new dataset, and then putting it back in the bag. You repeat this until your new dataset is the same size as the original. Because you're replacing the data points, some will appear multiple times in the new dataset, and some won't appear at all.
  2. Train in Parallel: Train an independent model (a "weak learner," like a decision tree) on each of the bootstrapped datasets. Since each model sees a slightly different version of the data, each will learn slightly different patterns and have different errors.
  3. Aggregate: For a new prediction, let all the models "vote" (for classification) or take the average of their outputs (for regression). The majority vote or the average becomes the final prediction of the ensemble.

This video provides an excellent high-level explanation of this process.

Master Ensemble Models: Bagging vs Boosting in Machine Learning EXPLAINED

This video from Super Data Science, "Master Ensemble Models," clearly explains the core idea behind Bagging.

Watch the section that explains how Bagging works. Pay close attention to the "bag" analogy for bootstrap aggregating.

By averaging the predictions from many models trained on different subsets of the data, Bagging effectively smooths out the predictions and reduces the risk of overfitting. It creates a stable, robust model that is less sensitive to the specific noise in the original training set.


3. Boosting: Reducing Bias Through Sequential Learning

Boosting is a different, and often more powerful, ensemble technique. While Bagging trains models in parallel, Boosting trains them sequentially. Each new model in the sequence is built to correct the errors made by the previous ones.

The general process for Boosting is as follows:

  1. Train an initial model: Start by training a very simple model on the original dataset.
  2. Identify errors: This first model will inevitably make mistakes, misclassifying some data points.
  3. Train the next model: The next model is trained specifically to focus on the data points that the previous model got wrong. This is often done by giving more "weight" or importance to the misclassified samples.
  4. Repeat: This process is repeated for a specified number of models. Each subsequent model learns from its predecessor's failures, gradually improving the overall performance on the "hard-to-classify" examples.
  5. Aggregate: The final prediction is a weighted average of all the models' predictions. Typically, models that performed better during training are given a higher weight in the final decision.

This video from DataMListic clearly illustrates this sequential, error-correcting process.

Bagging vs Boosting - Ensemble Learning In Machine Learning Explained

This video, "Bagging vs Boosting - Ensemble Learning In Machine Learning Explained," provides a concise explanation of how Boosting works.

Please watch the segment from the explanation of boosting, which details the sequential nature of training and the re-weighting of misclassified samples.

The core idea of Boosting is to turn a collection of weak learners (which may be only slightly better than random guessing) into a single, highly accurate strong learner. Its primary goal is to reduce bias by creating a model that fits the data more closely.


4. Bagging vs. Boosting: An Exam-Focused Comparison

For your exam, you will likely need to know the key differences between Bagging and Boosting. The following table provides a concise summary.

This table provides a clear comparison of Bagging, Boosting, and Stacking across four key characteristics. Note the primary purpose: Bagging reduces variance, while Boosting reduces bias.

Let's break down these differences, which are crucial for exam questions.

Scenario based interview questions for Data science Part - 3 | Kaggle

This Kaggle discussion post offers a very direct and concise answer to a common interview (and exam) question comparing Random Forest (a Bagging method) and Gradient Boosting (a Boosting method).

Read the answer to question 21, how is random forest different.

Based on this and our other resources, here are the key distinctions to remember:

  • Training Method:

    • Bagging: Models are trained in parallel and independently on different bootstrapped data subsets.
    • Boosting: Models are trained sequentially. Each new model is built to correct the errors of the previous one.
  • Primary Goal:

    • Bagging: To reduce variance and prevent overfitting. It is most effective with complex base models (like deep decision trees) that are prone to high variance.
    • Boosting: To reduce bias and prevent underfitting. It is effective at turning very simple models (like shallow decision trees or "stumps") into a powerful composite model.
  • Data Handling:

    • Bagging: Each model is trained on a random subset of the original data (bootstrapping). All data points in a subset are treated equally.
    • Boosting: The entire dataset is used for each model, but the weights of the data points are adjusted. Points that were misclassified by previous models are given higher weights.
  • Prediction Aggregation:

    • Bagging: Uses a simple democratic process—voting for classification or averaging for regression. Every model gets an equal say.
    • Boosting: Uses a weighted average. Models that performed better during training have more influence on the final prediction.

Conclusion

In this lesson, we moved beyond single models and into the powerful world of ensembles. You've learned how combining multiple "weak" models can create a single "strong" model that is far more accurate and reliable.

Here are your key takeaways for the exam:

  • Ensemble Learning is the process of combining multiple models to improve predictive performance.
  • Bagging (Bootstrap Aggregating) builds models in parallel on different random samples of the data. Its primary goal is to reduce variance (overfitting).
  • Boosting builds models sequentially, with each new model focusing on correcting the errors of the previous one. Its primary goal is to reduce bias (underfitting).
  • The core differences lie in their training process (parallel vs. sequential), their primary goal (variance vs. bias reduction), and how they combine predictions (equal vs. weighted voting).

Now that you understand the high-level concepts of Bagging and Boosting, our next lesson will get more concrete. We will explore two of the most famous and widely used ensemble algorithms: Random Forests (which uses Bagging) and Gradient Boosting, and discuss how they might appear in exam questions.