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.random.normal(0, dy)
y += noise
y = y.astype(np.float32)
# Mesh the input space for evaluations of the real function, the prediction and
# its MSE
xx = np.atleast_2d(np.linspace(0, 10, 1000)).T
xx = xx.astype(np.float32)
alpha = 0.95
clf = GradientBoostingRegressor(loss='quantile', alpha=alpha,
n_estimators=250, max_depth=3,
sklearn:梯度Boosting回归的预测区间
最新推荐文章于 2024-06-21 19:56:21 发布
本文深入探讨了sklearn库中梯度提升回归(Gradient Boosting Regression)的预测区间构建过程。通过分析算法的工作原理,结合实例展示了如何利用梯度提升模型进行不确定性估计,从而得到预测值的上下界。这对于理解和应用梯度提升模型在实际问题中的预测范围具有重要意义。
摘要由CSDN通过智能技术生成