The Wayback Machine - https://web.archive.org/web/20241125042027/https://www.geeksforgeeks.org/gradientboosting-vs-adaboost-vs-xgboost-vs-catboost-vs-lightgbm/
Open In App

GradientBoosting vs AdaBoost vs XGBoost vs CatBoost vs LightGBM

Last Updated : 29 May, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Boosting algorithms are one of the best-performing algorithms among all the other Machine Learning algorithms with the best performance and higher accuracies. All the boosting algorithms work on the basis of learning from the errors of the previous model trained and tried avoiding the same mistakes made by the previously trained weak learning algorithm.

It is also a big interview question that might be asked in data science interviews. In this article, we will be discussing the main difference between GradientBoosting, AdaBoost, XGBoost, CatBoost, and LightGBM algorithms, with their working mechanisms and their mathematics of them.

Gradient Boosting

Gradient Boosting is the boosting algorithm that works on the principle of the stagewise addition method, where multiple weak learning algorithms are trained and a strong learner algorithm is used as a final model from the addition of multiple weak learning algorithms trained on the same dataset.

In the gradient boosting algorithm, the first weak learner will not be trained on the dataset, it will simply return the mean of the particular column, and the residual for output of the first weak learner algorithm will be calculated which will be used as output or target column for next weak learning algorithm which is to be trained.

Following the same pattern, the second weak learner will be trained and the residuals will be calculated which will be used as an output column again for the next weak learner, this is how this process will continue until we reach zero residuals.

In gradient boosting the dataset should be in the form of numerical or categorical data and the loss function using which the residuals are calculated should be differential at all points.

Python3




from sklearn.ensemble import GradientBoostingRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split 
from sklearn.metrics import r2_score
 
X, y = make_regression(n_samples=100,
                       n_features=10,
                       n_informative=5,
                       n_targets=1,
                       random_state=42)
X_train, X_test,\
    y_train, y_test = train_test_split(X, y,
                                       test_size=0.2)
gbr = GradientBoostingRegressor()
gbr.fit(X_train, y_train)
y_pred1 = gbr.predict(X_test)
print("Gradient Boosting - R2: ",
      r2_score(y_test, y_pred1))


Output:

Gradient Boosting - R2:  0.8387570820958865 

XGBoost

XGBoost is also a boosting machine learning algorithm, which is the next version on top of the gradient boosting algorithm. The full name of the XGBoost algorithm is the eXtreme Gradient Boosting algorithm, as the name suggests it is an extreme version of the previous gradient boosting algorithm.

The main difference between GradientBoosting is XGBoost is that XGbost uses a regularization technique in it. In simple words, it is a regularized form of the existing gradient-boosting algorithm.

Due to this, XGBoost performs better than a normal gradient boosting algorithm and that is why it is much faster than that also. It also performs better when there is a presence of numerical and categorical features in the dataset.

Python3




from xgboost import XGBRegressor
xgr = XGBRegressor()
xgr.fit(X_train, y_train)
y_pred2 = xgr.predict(X_test)
print("XGBoost - R2: ",
      r2_score(y_test, y_pred2))


Output:

XGBoost - R2:  0.8730807521630943

AdaBoost

AdaBoost is a boosting algorithm, which also works on the principle of the stagewise addition method where multiple weak learners are used for getting strong learners. Unlike Gradient Boosting in XGBoost, the alpha parameter I calculated is related to the errors of the weak learner, here the value of the alpha parameter will be indirectly proportional to the error of the weak learner.

Once the alpha parameter is calculated, the weightage will be given to the particular weak learners, here the weak learner that are doing mistakes will get more weightage to fill out the gap in error and the weak learners that are already performing well will get fewer weights as they are already a good model.

Python3




from sklearn.ensemble import AdaBoostRegressor
adr = AdaBoostRegressor()
adr.fit(X_train, y_train)
y_pred3 = adr.predict(X_test)
print("AdaBoost - R2: ",
      r2_score(y_test, y_pred3))


Output:

AdaBoost - R2:  0.796880734337689

CatBoost

In CatBoost the main difference that makes it different and better than others is the growing of decision trees in it. In CatBoost the decision trees which is grown are symmetric. One can easily install this library by using the below command:

pip install catboost

CatBoost is a boosting algorithm that performs exceptionally very well on categorical datasets other than any algorithm in the field of machine learning as there is a special type of method for handling categorical datasets. In CatBoost, the categorical features are encoded on the basis of the output columns. So while training or encoding the categorical features, the weightage of the output column will also be considered which makes it higher accurate on categorical datasets.

Python3




from catboost import CatBoostRegressor
cbr = CatBoostRegressor(iterations=100,
                        depth=5,
                        learning_rate=0.01,
                        loss_function='RMSE',
                        verbose=0)
cbr.fit(X_train, y_train)
y_pred4 = cbr.predict(X_test)
print("CatBoost - R2: ",
      r2_score(y_test, y_pred4))


Output:

CatBoost - R2:  0.3405843849282183

LightGBM

LightGBM is also a boosting algorithm, which means Light Gradient Boosting Machine. It is used in the field of machine learning. In LightGBM decision trees are grown leaf wise meaning that at a single time only one leaf from the whole tree will be grown. One can install the required library by using the below command:

pip install lightgbm

LightGBM also works well on categorical datasets and it also handles the categorical features using the binning or bucketing method. To work with categorical features in LightGBM we have converted all the categorical features in the category datatype. Once done, there will be no need to handle categorical data as it will handle it automatically.

In LightGBM, the sampling of the data while training the decision tree is done by the method known as GOSS. In this method, the variance of all the data samples is calculated and sorted in descending order. Data samples having low variance are already performing well, so there will be less weightage given to the samples having low variance while sampling the dataset.

Python3




import lightgbm as lgb
from lightgbm import LGBMRegressor
lgr = LGBMRegressor()
lgr.fit(X_train, y_train)
y_pred5 = lgr.predict(X_test)
print("LightGBM - R2: ",
      r2_score(y_test, y_pred5))


Output:

LightGBM - R2:  0.8162904225442574

Difference Between Boosting Algorithms 

    Algorithms Gradient Boosting         AdaBoost              XGBoost             CatBoost             LightGBM     
Year     –     1995     2014    2017     2017 
Handling Categorical Variables May require preprocessing like one-hot encoding No NO Automatically handles categorical variables  No
Speed/Scalability Moderate Fast   Fast  Moderate Fast 
Memory Usage Moderate  Low  Moderate High  Low
Regularization NO  No Yes Yes Yes
Parallel Processing No No  Yes Yes Yes
GPU Support No No Yes Yes Yes
Feature Importance Available  Available Available Available Available

Which Boosting Algorithm to Use?

Now it is a very basic question, if all of these machine learning algorithms are the best performing, fast, and gives higher accuracies, then which to use?

Well, the answer to these questions can not be a single boosting algorithm among them as all of them are the best-fit solution for a particular type of problem on which we are working.

For example, If you think that there is a need for regularization according to your dataset, then you can definitely use XGBoost, If you want to deal with categorical data, then CatBoost and LightGBM perform very well on those types of datasets. If you need more community support for the algorithm then use algorithms which was developed years back XGBoost or Gradient Boosting.

Comparison Between Different Boosting Algorithms

After fitting the data to the model, all of the algorithms return almost similar kind of results. Here LightGBM seems to perform poorly compared to other algorithms and XGBoost performs well in this case.

To visualize the performance of all the algorithms on the same data, we can also plot the graph between the y_test and y_pred of all the algorithms.

Python3




import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(11, 5))
 
ax = sns.lineplot(x=y_test, y=y_pred1,
                  label='GradientBoosting')
ax1 = sns.lineplot(x=y_test, y=y_pred2,
                   label='XGBoost')
ax2 = sns.lineplot(x=y_test, y=y_pred3,
                   label='AdaBoost')
ax3 = sns.lineplot(x=y_test, y=y_pred4,
                   label='CatBoost')
ax4 = sns.lineplot(x=y_test, y=y_pred5,
                   label='LightGBM')
 
ax.set_xlabel('y_test', color='g')
ax.set_ylabel('y_pred', color='g')


Output:

Graph of y_pred v/s y_test

Graph of y_pred v/s y_test

We can see in the above chart, that represents the y_test and y_pred values predicted by every algorithm. Here we can see that LightGBM and CatBoost tend to perform poorly compared to other algorithms as they are predicting the values of y_pred very higher or lower than other algorithms. XGBoost and GradientBoosting perform well on this data, which we can clearly see from the image as their predictions seem like averaging of all the other algorithms from the graph.

Conclusion

In this article, the basic and mathematical difference between gradient boosting, XGBoost, AdaBoost, LightGBM, and CatBoost is discussed with their working mechanisms. Knowledge of these differences and core intuitions will help one to understand the difference between them better and help one to answer these types of questions very efficiently.



Previous Article
Next Article

Similar Reads

LightGBM vs XGBOOST - Which algorithm is better
There are a lot of Data Enthusiasts who are taking part in a number of online competitive competitions in the domain of Machine Learning. Everyone has their own unique independent approach to determine the best model and predict the accurate output of the given problem statement. In Machine Learning, Feature Engineering is very much an integral par
9 min read
Boosting in Machine Learning | Boosting and AdaBoost
A single weak model may not be enough for our complex problems such cases we aggregate various weak models to make a powerful and more accurate model for our problem this process of aggregating several small problems to create a strong model is what we do in boosting. What is Boosting Boosting is an ensemble modeling technique that attempts to buil
6 min read
Differences between Random Forest and AdaBoost
Random Forest Algorithm is a commonly used machine learning algorithm that combines the output of multiple Decision Trees to achieve a single result. It handles both classification and regression problems as it combines the simplicity of decision trees with flexibility leading to significant improvements in accuracy. AdaBoost Algorithm (Adaptive Bo
4 min read
Implementing the AdaBoost Algorithm From Scratch
In this article, we will learn about the AdaBoost classifier and its practical implementation over a dataset.AdaBoost algorithm falls under ensemble boosting techniques, as we will discuss it combines multiple models to produce more accurate results and this is done in two phases: Multiple weak learners are allowed to learn on training dataCombinin
6 min read
Adaboost Using Caret Package in R
Adaboost (Adaptive Boosting) is an ensemble learning technique that combines multiple weak classifiers to create a strong classifier. The caret package in R provides a convenient interface for training Adaboost models, along with numerous other machine-learning algorithms. This article will walk you through the theory behind Adaboost and demonstrat
4 min read
XGBoost for Regression
The results of the regression problems are continuous or real values. Some commonly used regression algorithms are Linear Regression and Decision Trees. There are several metrics involved in regression like root-mean-squared error (RMSE) and mean-squared-error (MSE). These are some key members of XGBoost models, each plays an important role. RMSE:
7 min read
XGBoost
XGBoost is an optimized distributed gradient boosting library designed for efficient and scalable training of machine learning models. It is an ensemble learning method that combines the predictions of multiple weak models to produce a stronger prediction. XGBoost stands for "Extreme Gradient Boosting" and it has become one of the most popular and
12 min read
ML | XGBoost (eXtreme Gradient Boosting)
XGBoost, short for eXtreme Gradient Boosting, is a powerful machine learning algorithm known for its efficiency, speed, and accuracy. It belongs to the family of boosting algorithms, which are ensemble learning techniques that combine the predictions of multiple weak learners. In this article, we will explore XGBoost step by step, building on exist
12 min read
What is the Need of XGBoost and Random Forest?
Answer: XGBoost and Random Forest are ensemble learning algorithms that enhance predictive accuracy and handle complex relationships in machine learning by leveraging multiple decision trees.Random Forest: High Predictive Accuracy:Random Forest is an ensemble learning method that builds multiple decision trees and combines their predictions. This e
3 min read
Difference Between Random Forest and XGBoost
Random Forest and XGBoost are both powerful machine learning algorithms widely used for classification and regression tasks. While they share some similarities in their ensemble-based approaches, they differ in their algorithmic techniques, handling of overfitting, performance, flexibility, and parameter tuning. In this tutorial, we will understand
6 min read
XGBoost in R Programming
XGBoost is a popular machine learning algorithm and it stands for "Extreme Gradient Boosting." XGBoost is available in various programming languages, including R. An XGBoost is a fast and efficient algorithm. XG Boost works only with numeric variables. and XGBoost is a fast and efficient algorithm and is used by winners of many machine learning com
6 min read
Confidence Intervals for XGBoost
Confidence intervals provide a range within which we expect the true value of a parameter to lie, with a certain level of confidence. In the context of XGBoost, confidence intervals can be used to quantify the uncertainty of predictions. In this article we explain how to compute confidence intervals for predictions made by an XGBoost model. What ar
4 min read
How to Get Access of Individual Trees of a XGBoost Model in R
XGBoost is a powerful and popular machine-learning algorithm used for regression and classification tasks. It stands out for its performance and efficiency, making it a top choice for data scientists. Understanding the structure of individual trees in an XGBoost model can be crucial for interpretation and debugging purposes. This article will guide
4 min read
XGBoost in R: How Does xgb.cv Pass the Optimal Parameters into xgb.train
XGBoost is a powerful gradient-boosting algorithm known for its efficiency and effectiveness in handling structured data. When tuning hyperparameters for an XGBoost model, cross-validation (CV) is commonly used to find the optimal combination of parameters. The xgb.cv function in R performs cross-validation to identify the best parameters, but how
5 min read
Saving and Loading XGBoost Models
XGBoost is a powerful and widely-used gradient boosting library that has become a staple in machine learning. Its ability to handle large datasets and provide accurate results makes it a popular choice among data scientists. However, one crucial aspect of working with XGBoost models is saving and loading them for future use. In this article, we wil
7 min read
Difference between Objective and feval in xgboost in R
XGBoost is a powerful machine-learning library that efficiently implements gradient boosting. It is widely used for its performance and flexibility. In XGBoost, two key parameters that often come up during model training are objective and feval. Understanding their differences is crucial for effectively leveraging the library's capabilities. Overvi
6 min read
How to use XGBoost algorithm for regression in R?
XGBoost (Extreme Gradient Boosting) is a powerful machine learning algorithm based on gradient boosting that is widely used for classification and regression tasks. In this article, we will explain how to use XGBoost for regression in R. What is XGBoost?The XGBoost stands for "Extreme Gradient Boosting." It is a powerful machine learning technique
4 min read
Different Results: “xgboost” vs. “caret” in R
When working with machine learning models in R, you may encounter different results depending on whether you use the xgboost package directly or through the caret package. This article explores why these differences occur and how to manage them to ensure consistent and reliable model performance. Introduction to xgboost and Caretxgboost is a powerf
4 min read
Confidence interval for xgboost regression in R
XGBoost is Designed to be highly efficient, versatile, and portable, it is an optimized distributed gradient boosting library. Under the Gradient Boosting framework, it puts machine learning techniques into practice. Many data science problems can be swiftly and precisely resolved with XGBoost's parallel tree boosting, also referred to as GBDT or G
4 min read
Partial Dependence Plot from an XGBoost Model in R
Partial Dependence Plots (PDPs) are a powerful tool for interpreting complex machine-learning models. They help visualize the relationship between a subset of features and the predicted outcome, holding other features constant. In the context of XGBoost models, PDPs can provide insights into how specific features influence the model's predictions.
4 min read
What is the Difference Between eval_metric and feval in XGBoost in R?
When using XGBoost in R, two important parameters that often confuse are eval_metric and feval. These parameters play a crucial role in model evaluation, but they serve different purposes. In this article, we'll delve into the theory behind eval_metric and feval, explore their differences, and provide examples to illustrate how to use them in pract
5 min read
How is the Feature Score(Importance) in the XGBoost Package Calculated Using R?
XGBoost (Extreme Gradient Boosting) is one of the most popular machine learning algorithms due to its high performance and efficiency in handling structured data. Understanding which features contribute most to the model's predictions can be crucial, especially in real-world applications where interpretability is essential. This process is called f
4 min read
Automated Music Genre Classification using Librosa and XGBOOST
Music genre classification is a critical task in the field of music information retrieval, which aims to categorize music tracks into predefined genres based on their audio features. This process is essential for organizing large music libraries, enhancing music recommendation systems, and providing valuable insights into musical trends. In this ar
10 min read
LightGBM Model evaluation metrics
LightGBM (Light Gradient Boosting Machine) is a popular gradient boosting framework developed by Microsoft known for its speed and efficiency in training large datasets. It's widely used for various machine-learning tasks, including classification, regression, and ranking. While training a LightGBM model is relatively straightforward, evaluating it
10 min read
Binary classification using LightGBM
In this article, we will learn about one of the state-of-the-art machine learning models: Lightgbm or light gradient boosting machine. After improvising more and more on the XGB model for better performance XGBoost which is an eXtreme Gradient Boosting machine but by the lightgbm we can achieve similar or better results without much computing and t
12 min read
Multiclass classification using LightGBM
While solving problems in real life it is very rare that we only come across binary classification problems because there are times when we have to classify within multiple categories for example dealing with the iris problem or the MNIST dataset is one of the common multiclass classification problems. As the researchers are developing the state of
10 min read
Train a model using LightGBM
Light Gradient Boosting Machine (LightGBM) is an open-source and distributed gradient boosting framework that was developed by Microsoft Corporation. Unlike other traditional machine learning models, LightGBM can efficiently large datasets and has optimized training processes. LightGBM can be employed in classification, regression, and also in rank
11 min read
LightGBM Leaf-wise Tree Growth Strategy
When it comes to machine learning and data analysis, decision trees are a fundamental tool used for classification and regression tasks. LightGBM is a popular gradient-boosting framework that employs an innovative tree growth strategy known as "leaf-wise" growth. One of the key features of LightGBM is its leaf-wise tree growth strategy, which diffe
9 min read
LightGBM Gradient-Based Strategy
LightGBM is a well-known high-performing model that uses a gradient-based strategy in its internal training process. Gradient-based strategy effectively enhances a model to make it highly optimized, accurate in prediction, and memory efficient which unlocks an easy way to handle complex and large real-world datasets used in various machine learning
9 min read
Cross-validation and Hyperparameter tuning of LightGBM Model
In a variety of industries, including finance, healthcare, and marketing, machine learning models have become essential for resolving challenging real-world issues. Gradient boosting techniques have become incredibly popular among the myriad of machine learning algorithms due to their remarkable prediction performance. Due to its speed and effectiv
14 min read
three90RightbarBannerImg