实验代码
本文采用python sklearn库中,作为quantile regression的示例代码。以下为详细解析:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import GradientBoostingRegressor
%matplotlib inline
np.random.seed(1)
#设置随机数生成的种子
def f(x):
"""The function to predict."""
return x * np.sin(x)
#对x取正弦
#----------------------------------------------------------------------
# First the noiseless case
X = np.atleast_2d(np.random.uniform(0, 10.0, size=100)).T
# 随机采样并转换成数组
# numpy.atleast_2d()其他格式转换成数组
# numpy.random.uniform(low,high,size) 从一个均匀分布[low,high)中随机采样,注意定义域是左闭右开,即包含low,不包含high.
# .T 数组转置.
X = X.astype(np.float32)
#转换数据类型 float32 减少精度
# Observations
y = f(X)