Example: Prediction Intervals for Gradient Boosting Regression

Prediction Intervals for Gradient Boosting Regression

This example shows how quantile regression can be used to create prediction intervals.

../../_images/sphx_glr_plot_gradient_boosting_quantile_001.png
import numpy as np
import matplotlib.pyplot as plt

from sklearn.ensemble import GradientBoostingRegressor

np.random.seed(1)


def f(x):
    """The function to predict."""
    return x * np.sin(x)

#----------------------------------------------------------------------
#  First the noiseless case
X = np.atleast_2d(np.random.uniform(0, 10.0, size=100)).T
X = X.astype(np.float32)

# Observations
y = f(X).ravel()

dy = 1.5 + 1.0 * np.random.random(y.shape)
noise = np