Ensemble Methods, Bagging and Boosting
Ensemble methods involve group of predictive models to achieve a better accuracy and model stability. Ensemble methods are known to impart supreme boost to tree based models.
Like every other model, a tree based model also suffers from the plague of bias and variance. Bias means, ‘how much on an average are the predicted values different from the actual value.’ Variance means, ‘how different will the predictions of the model be at the same point if different samples are taken from the same population’.
You build a small tree and you will get a model with low variance and high bias. How do you manage to balance the trade off between bias and variance ?
Normally, as you increase the complexity of your model, you will see a reduction in prediction error due to lower bias in the model. As you continue to make your model more complex, you end up overfitting your model and your model will start suffering from high variance.
A champion model should maintain a balance between these two types of errors. This is known as the tradeoff management of biasvariance errors. Ensemble learning is one way to execute this trade off analysis.
Some of the commonly used ensemble methods include: Bagging, Boosting and Stacking.
Bagging
Bagging is a technique used to reduce the variance of our predictions by combining the result of multiple classifiers modeled on different subsamples of the same data set. The following figure will make it clearer:
The steps followed in bagging are:
Create Multiple DataSets:
 Sampling is done with replacement on the original data and new datasets are formed.
 The new data sets can have a fraction of the columns as well as rows, which are generally hyperparameters in a bagging model
 Taking row and column fractions less than 1 helps in making robust models, less prone to overfitting
Build Multiple Classifiers:
 Classifiers are built on each data set.
 Generally the same classifier is modeled on each data set and predictions are made.
 Combine Classifiers:

 The predictions of all the classifiers are combined using a mean, median or mode value depending on the problem at hand.
 The combined values are generally more robust than a single model.
Note that, here the number of models built is not a hyperparameters. Higher number of models are always better or may give similar performance than lower numbers. It can be theoretically shown that the variance of the combined predictions are reduced to 1/n (n: number of classifiers) of the original variance, under some assumptions.
Random Forest is a type of Bagging Algorithm
Boosting
The term ‘Boosting’ refers to a family of algorithms which converts weak learner to strong learners.
Boosting combines weak learner a.k.a. base learner to form a strong rule. An immediate question which should pop in your mind is, ‘How boosting identify weak rules?
To find weak rule, we apply base learning (ML) algorithms with a different distribution. Each time base learning algorithm is applied, it generates a new weak prediction rule. This is an iterative process. After many iterations, the boosting algorithm combines these weak rules into a single strong prediction rule.
Here’s another question which might haunt you, ‘How do we choose different distribution for each round?’
For choosing the right distribution, here are the following steps:
Step 1: The base learner takes all the distributions and assign equal weight or attention to each observation.
Step 2: If there is any prediction error caused by first base learning algorithm, then we pay higher attention to observations having prediction error. Then, we apply the next base learning algorithm.
Step 3: Iterate Step 2 till the limit of base learning algorithm is reached or higher accuracy is achieved.
Finally, it combines the outputs from weak learner and creates a strong learner which eventually improves the prediction power of the model. Boosting pays higher focus on examples which are misclassiﬁed or have higher errors by preceding weak rules.
There are many boosting algorithms which impart additional boost to model’s accuracy. In this tutorial, we’ll learn about the two most commonly used algorithms i.e. Gradient Boosting (GBM) and XGboost.
Details on XGBoost and GBM will be in another post
Article Source: AnalyticsVidhya