Gradient Boosting is one of the most important ensemble learning techniques used in machine learning.
It builds multiple models sequentially, where each new model tries to correct the errors made by the previous models.
Let's understand how it works.
Gradient Boosting is an ensemble learning algorithm that combines multiple weak prediction models to create a strong predictive model.
It generally uses Decision Trees as its base learners.
Unlike Random Forest, where trees are built independently, Gradient Boosting builds trees sequentially.
Let's understand the process:
The final prediction combines the contributions of all the trained models.
Suppose we want to predict house prices.
Actual price: โน50 lakh
Initial prediction: โน40 lakh
Error: โน10 lakh
The next tree tries to learn this error and improve the prediction.
After multiple iterations, the model may produce a prediction much closer to the actual price.
This is the basic intuition behind Gradient Boosting.
Learning Rate
Controls how much each new tree contributes to the overall prediction.
A smaller learning rate means slower learning but may improve generalization when combined with more trees.
Number of Estimators
The number of boosting stages or trees.
Maximum Depth
Controls how deep each individual tree can grow.
Loss Function
Measures how far predictions are from actual values. The algorithm tries to minimize this loss.
We can implement Gradient Boosting using Scikit-learn.
from sklearn.metrics import accuracy_score
model = GradientBoostingClassifier(
n_estimators=100,
learning_rate=0.1,
max_depth=3,
random_state=42
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(accuracy_score(y_test, predictions))
Gradient Boosting can also predict numerical values.
For example:
- House prices
- Sales forecasting
- Revenue prediction
- Demand estimation
Python example:
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.metrics import mean_absolute_error
model = GradientBoostingRegressor(
n_estimators=100,
learning_rate=0.1,
max_depth=3,
random_state=42
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(mean_absolute_error(y_test, predictions))
Random Forest
- Uses Bagging.
- Trees are built independently.
- Reduces variance by combining predictions.
- Usually easier to tune.
Gradient Boosting
- Uses Boosting.
- Trees are built sequentially.
- Each new tree attempts to improve previous predictions.
- Requires careful hyperparameter tuning.
โ Can achieve strong predictive performance.
Some important algorithms and libraries you should know:
- Gradient Boosting โ Scikit-learn
- XGBoost โ Extreme Gradient Boosting
- LightGBM โ Light Gradient Boosting Machine
- CatBoost โ Gradient boosting designed to handle categorical features effectively
These are widely used in machine learning competitions and real-world predictive analytics.
Remember:
- Random Forest โ Trees work independently.
- Gradient Boosting โ Trees learn sequentially.
- Learning Rate โ Controls each tree's contribution.
- Number of Estimators โ Controls the number of boosting stages.




