Gradient boosting is a powerful ensemble machine learning algorithm.
It’s popular for structured predictive modeling problems, such as classification and regression on tabular data, and is often the main algorithm or one of the main algorithms used in winning solutions to machine learning competitions, like those on Kaggle.
There are many implementations of gradient boosting available, including standard implementations in SciPy and efficient thirdparty libraries. Each uses a different interface and even different names for the algorithm.
In this tutorial, you will discover how to use gradient boosting models for classification and regression in Python.
Standardized code examples are provided for the four major implementations of gradient boosting in Python, ready for you to copypaste and use in your own predictive modeling project.
After completing this tutorial, you will know:
 Gradient boosting is an ensemble algorithm that fits boosted decision trees by minimizing an error gradient.
 How to evaluate and use gradient boosting with scikitlearn, including gradient boosting machines and the histogrambased algorithm.
 How to evaluate and use thirdparty gradient boosting algorithms, including XGBoost, LightGBM, and CatBoost.
Let’s get started.
Tutorial Overview
This tutorial is divided into five parts; they are:
 Gradient Boosting Overview
 Gradient Boosting With ScikitLearn
 Library Installation
 Test Problems
 Gradient Boosting
 HistogramBased Gradient Boosting
 Gradient Boosting With XGBoost
 Library Installation
 XGBoost for Classification
 XGBoost for Regression
 Gradient Boosting With LightGBM
 Library Installation
 LightGBM for Classification
 LightGBM for Regression
 Gradient Boosting With CatBoost
 Library Installation
 CatBoost for Classification
 CatBoost for Regression
Gradient Boosting Overview
Gradient boosting refers to a class of ensemble machine learning algorithms that can be used for classification or regression predictive modeling problems.
Gradient boosting is also known as gradient tree boosting, stochastic gradient boosting (an extension), and gradient boosting machines, or GBM for short.
Ensembles are constructed from decision tree models. Trees are added one at a time to the ensemble and fit to correct the prediction errors made by prior models. This is a type of ensemble machine learning model referred to as boosting.
Models are fit using any arbitrary differentiable loss function and gradient descent optimization algorithm. This gives the technique its name, “gradient boosting,” as the loss gradient is minimized as the model is fit, much like a neural network.
Gradient boosting is an effective machine learning algorithm and is often the main, or one of the main, algorithms used to win machine learning competitions (like Kaggle) on tabular and similar structured datasets.
Note: We will not be going into the theory behind how the gradient boosting algorithm works in this tutorial.
For more on the gradient boosting algorithm, see the tutorial:
The algorithm provides hyperparameters that should, and perhaps must, be tuned for a specific dataset. Although there are many hyperparameters to tune, perhaps the most important are as follows:
 The number of trees or estimators in the model.
 The learning rate of the model.
 The row and column sampling rate for stochastic models.
 The maximum tree depth.
 The minimum tree weight.
 The regularization terms alpha and lambda.
Note: We will not be exploring how to configure or tune the configuration of gradient boosting algorithms in this tutorial.
For more on tuning the hyperparameters of gradient boosting algorithms, see the tutorial:
There are many implementations of the gradient boosting algorithm available in Python. Perhaps the most used implementation is the version provided with the scikitlearn library.
Additional thirdparty libraries are available that provide computationally efficient alternate implementations of the algorithm that often achieve better results in practice. Examples include the XGBoost library, the LightGBM library, and the CatBoost library.
Do you have a different favorite gradient boosting implementation?
Let me know in the comments below.
When using gradient boosting on your predictive modeling project, you may want to test each implementation of the algorithm.
This tutorial provides examples of each implementation of the gradient boosting algorithm on classification and regression predictive modeling problems that you can copypaste into your project.
Let’s take a look at each in turn.
Note: We are not comparing the performance of the algorithms in this tutorial. Instead, we are providing code examples to demonstrate how to use each different implementation. As such, we are using synthetic test datasets to demonstrate evaluating and making a prediction with each implementation.
This tutorial assumes you have Python and SciPy installed. If you need help, see the tutorial:
Gradient Boosting with ScikitLearn
In this section, we will review how to use the gradient boosting algorithm implementation in the scikitlearn library.
Library Installation
First, let’s install the library.
Don’t skip this step as you will need to ensure you have the latest version installed.
You can install the scikitlearn library using the pip Python installer, as follows:

sudo pip install scikitlearn 
For additional installation instructions specific to your platform, see:
Next, let’s confirm that the library is installed and you are using a modern version.
Run the following script to print the library version number.

# check scikitlearn version import sklearn print(sklearn.__version__) 
Running the example, you should see the following version number or higher.
Test Problems
We will demonstrate the gradient boosting algorithm for classification and regression.
As such, we will use synthetic test problems from the scikitlearn library.
Classification Dataset
We will use the make_classification() function to create a test binary classification dataset.
The dataset will have 1,000 examples, with 10 input features, five of which will be informative and the remaining five that will be redundant. We will fix the random number seed to ensure we get the same examples each time the code is run.
An example of creating and summarizing the dataset is listed below.

# test classification dataset from sklearn.datasets import make_classification # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # summarize the dataset print(X.shape, y.shape) 
Running the example creates the dataset and confirms the expected number of samples and features.
Regression Dataset
We will use the make_regression() function to create a test regression dataset.
Like the classification dataset, the regression dataset will have 1,000 examples, with 10 input features, five of which will be informative and the remaining five that will be redundant.

# test regression dataset from sklearn.datasets import make_regression # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # summarize the dataset print(X.shape, y.shape) 
Running the example creates the dataset and confirms the expected number of samples and features.
Next, let’s look at how we can develop gradient boosting models in scikitlearn.
Gradient Boosting
The scikitlearn library provides the GBM algorithm for regression and classification via the GradientBoostingClassifier and GradientBoostingRegressor classes.
Let’s take a closer look at each in turn.
Gradient Boosting Machine for Classification
The example below first evaluates a GradientBoostingClassifier on the test problem using repeated kfold crossvalidation and reports the mean accuracy. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# gradient boosting for classification in scikitlearn from numpy import mean from numpy import std from sklearn.datasets import make_classification from sklearn.ensemble import GradientBoostingClassifier from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedStratifiedKFold from matplotlib import pyplot # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # evaluate the model model = GradientBoostingClassifier() cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘accuracy’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘Accuracy: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = GradientBoostingClassifier() model.fit(X, y) # make a single prediction row = [[2.56999479, –0.13019997, 3.16075093, –4.35936352, –1.61271951, –1.39352057, –2.48924933, –1.93094078, 3.26130366, 2.05692145]] yhat = model.predict(row) print(‘Prediction: %d’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

Accuracy: 0.915 (0.025) Prediction: 1 
Gradient Boosting Machine for Regression
The example below first evaluates a GradientBoostingRegressor on the test problem using repeated kfold crossvalidation and reports the mean absolute error. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# gradient boosting for regression in scikitlearn from numpy import mean from numpy import std from sklearn.datasets import make_regression from sklearn.ensemble import GradientBoostingRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedKFold from matplotlib import pyplot # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # evaluate the model model = GradientBoostingRegressor() cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘neg_mean_absolute_error’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘MAE: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = GradientBoostingRegressor() model.fit(X, y) # make a single prediction row = [[2.02220122, 0.31563495, 0.82797464, –0.30620401, 0.16003707, –1.44411381, 0.87616892, –0.50446586, 0.23009474, 0.76201118]] yhat = model.predict(row) print(‘Prediction: %.3f’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

MAE: 11.854 (1.121) Prediction: 80.661 
HistogramBased Gradient Boosting
The scikitlearn library provides an alternate implementation of the gradient boosting algorithm, referred to as histogrambased gradient boosting.
This is an alternate approach to implement gradient tree boosting inspired by the LightGBM library (described more later). This implementation is provided via the HistGradientBoostingClassifier and HistGradientBoostingRegressor classes.
The primary benefit of the histogrambased approach to gradient boosting is speed. These implementations are designed to be much faster to fit on training data.
At the time of writing, this is an experimental implementation and requires that you add the following line to your code to enable access to these classes.

from sklearn.experimental import enable_hist_gradient_boosting 
Without this line, you will see an error like:

ImportError: cannot import name ‘HistGradientBoostingClassifier’ 
or

ImportError: cannot import name ‘HistGradientBoostingRegressor’ 
Let’s take a close look at how to use this implementation.
HistogramBased Gradient Boosting Machine for Classification
The example below first evaluates a HistGradientBoostingClassifier on the test problem using repeated kfold crossvalidation and reports the mean accuracy. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

# histogrambased gradient boosting for classification in scikitlearn from numpy import mean from numpy import std from sklearn.datasets import make_classification from sklearn.experimental import enable_hist_gradient_boosting from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedStratifiedKFold from matplotlib import pyplot # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # evaluate the model model = HistGradientBoostingClassifier() cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘accuracy’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘Accuracy: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = HistGradientBoostingClassifier() model.fit(X, y) # make a single prediction row = [[2.56999479, –0.13019997, 3.16075093, –4.35936352, –1.61271951, –1.39352057, –2.48924933, –1.93094078, 3.26130366, 2.05692145]] yhat = model.predict(row) print(‘Prediction: %d’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

Accuracy: 0.935 (0.024) Prediction: 1 
HistogramBased Gradient Boosting Machine for Regression
The example below first evaluates a HistGradientBoostingRegressor on the test problem using repeated kfold crossvalidation and reports the mean absolute error. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

# histogrambased gradient boosting for regression in scikitlearn from numpy import mean from numpy import std from sklearn.datasets import make_regression from sklearn.experimental import enable_hist_gradient_boosting from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedKFold from matplotlib import pyplot # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # evaluate the model model = HistGradientBoostingRegressor() cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘neg_mean_absolute_error’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘MAE: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = HistGradientBoostingRegressor() model.fit(X, y) # make a single prediction row = [[2.02220122, 0.31563495, 0.82797464, –0.30620401, 0.16003707, –1.44411381, 0.87616892, –0.50446586, 0.23009474, 0.76201118]] yhat = model.predict(row) print(‘Prediction: %.3f’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

MAE: 12.723 (1.540) Prediction: 77.837 
Gradient Boosting With XGBoost
XGBoost, which is short for “Extreme Gradient Boosting,” is a library that provides an efficient implementation of the gradient boosting algorithm.
The main benefit of the XGBoost implementation is computational efficiency and often better model performance.
For more on the benefits and capability of XGBoost, see the tutorial:
Library Installation
You can install the XGBoost library using the pip Python installer, as follows:
For additional installation instructions specific to your platform see:
Next, let’s confirm that the library is installed and you are using a modern version.
Run the following script to print the library version number.

# check xgboost version import xgboost print(xgboost.__version__) 
Running the example, you should see the following version number or higher.
The XGBoost library provides wrapper classes so that the efficient algorithm implementation can be used with the scikitlearn library, specifically via the XGBClassifier and XGBregressor classes.
Let’s take a closer look at each in turn.
XGBoost for Classification
The example below first evaluates an XGBClassifier on the test problem using repeated kfold crossvalidation and reports the mean accuracy. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

# xgboost for classification from numpy import asarray from numpy import mean from numpy import std from sklearn.datasets import make_classification from xgboost import XGBClassifier from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedStratifiedKFold from matplotlib import pyplot # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # evaluate the model model = XGBClassifier() cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘accuracy’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘Accuracy: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = XGBClassifier() model.fit(X, y) # make a single prediction row = [2.56999479, –0.13019997, 3.16075093, –4.35936352, –1.61271951, –1.39352057, –2.48924933, –1.93094078, 3.26130366, 2.05692145] row = asarray(row).reshape((1, len(row))) yhat = model.predict(row) print(‘Prediction: %d’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

Accuracy: 0.936 (0.019) Prediction: 1 
XGBoost for Regression
The example below first evaluates an XGBRegressor on the test problem using repeated kfold crossvalidation and reports the mean absolute error. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

# xgboost for regression from numpy import asarray from numpy import mean from numpy import std from sklearn.datasets import make_regression from xgboost import XGBRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedKFold from matplotlib import pyplot # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # evaluate the model model = XGBRegressor(objective=‘reg:squarederror’) cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘neg_mean_absolute_error’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘MAE: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = XGBRegressor(objective=‘reg:squarederror’) model.fit(X, y) # make a single prediction row = [2.02220122, 0.31563495, 0.82797464, –0.30620401, 0.16003707, –1.44411381, 0.87616892, –0.50446586, 0.23009474, 0.76201118] row = asarray(row).reshape((1, len(row))) yhat = model.predict(row) print(‘Prediction: %.3f’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

MAE: 15.048 (1.316) Prediction: 93.434 
Gradient Boosting With LightGBM
LightGBM, short for Light Gradient Boosted Machine, is a library developed at Microsoft that provides an efficient implementation of the gradient boosting algorithm.
The primary benefit of the LightGBM is the changes to the training algorithm that make the process dramatically faster, and in many cases, result in a more effective model.
For more technical details on the LightGBM algorithm, see the paper:
Library Installation
You can install the LightGBM library using the pip Python installer, as follows:

sudo pip install lightgbm 
For additional installation instructions specific to your platform, see:
Next, let’s confirm that the library is installed and you are using a modern version.
Run the following script to print the library version number.

# check lightgbm version import lightgbm print(lightgbm.__version__) 
Running the example, you should see the following version number or higher.
The LightGBM library provides wrapper classes so that the efficient algorithm implementation can be used with the scikitlearn library, specifically via the LGBMClassifier and LGBMRegressor classes.
Let’s take a closer look at each in turn.
LightGBM for Classification
The example below first evaluates an LGBMClassifier on the test problem using repeated kfold crossvalidation and reports the mean accuracy. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# lightgbm for classification from numpy import mean from numpy import std from sklearn.datasets import make_classification from lightgbm import LGBMClassifier from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedStratifiedKFold from matplotlib import pyplot # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # evaluate the model model = LGBMClassifier() cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘accuracy’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘Accuracy: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = LGBMClassifier() model.fit(X, y) # make a single prediction row = [[2.56999479, –0.13019997, 3.16075093, –4.35936352, –1.61271951, –1.39352057, –2.48924933, –1.93094078, 3.26130366, 2.05692145]] yhat = model.predict(row) print(‘Prediction: %d’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

Accuracy: 0.934 (0.021) Prediction: 1 
LightGBM for Regression
The example below first evaluates an LGBMRegressor on the test problem using repeated kfold crossvalidation and reports the mean absolute error. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# lightgbm for regression from numpy import mean from numpy import std from sklearn.datasets import make_regression from lightgbm import LGBMRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedKFold from matplotlib import pyplot # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # evaluate the model model = LGBMRegressor() cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘neg_mean_absolute_error’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘MAE: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = LGBMRegressor() model.fit(X, y) # make a single prediction row = [[2.02220122, 0.31563495, 0.82797464, –0.30620401, 0.16003707, –1.44411381, 0.87616892, –0.50446586, 0.23009474, 0.76201118]] yhat = model.predict(row) print(‘Prediction: %.3f’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

MAE: 12.739 (1.408) Prediction: 82.040 
Gradient Boosting with CatBoost
CatBoost is a thirdparty library developed at Yandex that provides an efficient implementation of the gradient boosting algorithm.
The primary benefit of the CatBoost (in addition to computational speed improvements) is support for categorical input variables. This gives the library its name CatBoost for “Category Gradient Boosting.”
For more technical details on the CatBoost algorithm, see the paper:
Library Installation
You can install the CatBoost library using the pip Python installer, as follows:

sudo pip install catboost 
For additional installation instructions specific to your platform, see:
Next, let’s confirm that the library is installed and you are using a modern version.
Run the following script to print the library version number.

# check catboost version import catboost print(catboost.__version__) 
Running the example, you should see the following version number or higher.
The CatBoost library provides wrapper classes so that the efficient algorithm implementation can be used with the scikitlearn library, specifically via the CatBoostClassifier and CatBoostRegressor classes.
Let’s take a closer look at each in turn.
CatBoost for Classification
The example below first evaluates a CatBoostClassifier on the test problem using repeated kfold crossvalidation and reports the mean accuracy. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# catboost for classification from numpy import mean from numpy import std from sklearn.datasets import make_classification from catboost import CatBoostClassifier from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedStratifiedKFold from matplotlib import pyplot # define dataset X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=5, random_state=1) # evaluate the model model = CatBoostClassifier(verbose=0, n_estimators=100) cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘accuracy’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘Accuracy: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = CatBoostClassifier(verbose=0, n_estimators=100) model.fit(X, y) # make a single prediction row = [[2.56999479, –0.13019997, 3.16075093, –4.35936352, –1.61271951, –1.39352057, –2.48924933, –1.93094078, 3.26130366, 2.05692145]] yhat = model.predict(row) print(‘Prediction: %d’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

Accuracy: 0.931 (0.026) Prediction: 1 
CatBoost for Regression
The example below first evaluates a CatBoostRegressor on the test problem using repeated kfold crossvalidation and reports the mean absolute error. Then a single model is fit on all available data and a single prediction is made.
The complete example is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

# catboost for regression from numpy import mean from numpy import std from sklearn.datasets import make_regression from catboost import CatBoostRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import RepeatedKFold from matplotlib import pyplot # define dataset X, y = make_regression(n_samples=1000, n_features=10, n_informative=5, random_state=1) # evaluate the model model = CatBoostRegressor(verbose=0, n_estimators=100) cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(model, X, y, scoring=‘neg_mean_absolute_error’, cv=cv, n_jobs=–1, error_score=‘raise’) print(‘MAE: %.3f (%.3f)’ % (mean(n_scores), std(n_scores))) # fit the model on the whole dataset model = CatBoostRegressor(verbose=0, n_estimators=100) model.fit(X, y) # make a single prediction row = [[2.02220122, 0.31563495, 0.82797464, –0.30620401, 0.16003707, –1.44411381, 0.87616892, –0.50446586, 0.23009474, 0.76201118]] yhat = model.predict(row) print(‘Prediction: %.3f’ % yhat[0]) 
Running the example first reports the evaluation of the model using repeated kfold crossvalidation, then the result of making a single prediction with a model fit on the entire dataset.

MAE: 9.281 (0.951) Prediction: 74.212 
Further Reading
This section provides more resources on the topic if you are looking to go deeper.
Tutorials
Papers
APIs
Articles
Summary
In this tutorial, you discovered how to use gradient boosting models for classification and regression in Python.
Specifically, you learned:
 Gradient boosting is an ensemble algorithm that fits boosted decision trees by minimizing an error gradient.
 How to evaluate and use gradient boosting with scikitlearn, including gradient boosting machines and the histogrambased algorithm.
 How to evaluate and use thirdparty gradient boosting algorithms including XGBoost, LightGBM and CatBoost.
Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.