Python 3.x 从单个决策树计算梯度增强回归值

Python 3.x 从单个决策树计算梯度增强回归值,python-3.x,scikit-learn,Python 3.x,Scikit Learn,我试图使用GBR的单个决策树来计算GBR的值。我认为这就像预测每一棵树一样简单,通过学习率进行缩放,并将结果相加,但当我直接通过GBR进行预测时,我没有得到相同的值,我想知道我对GBR预测是如何计算的理解是否有差距(我甚至尝试过深入研究SKL代码,它似乎也在做我想要做的事情) 简而言之,我的代码如下所示: gbr = GradientBoostingRegressor( max_depth=3, learning_rate=0.1, n_estimators=50 #

我试图使用GBR的单个决策树来计算GBR的值。我认为这就像预测每一棵树一样简单,通过学习率进行缩放,并将结果相加,但当我直接通过GBR进行预测时,我没有得到相同的值,我想知道我对GBR预测是如何计算的理解是否有差距(我甚至尝试过深入研究SKL代码,它似乎也在做我想要做的事情)

简而言之,我的代码如下所示:

gbr = GradientBoostingRegressor(
    max_depth=3,
    learning_rate=0.1,
    n_estimators=50  # number of trees
)

gbr.fit(X,y)  # X is a dataframe which is why you'll see me converting it to numpy and reshaping later

X_sample = X.iloc[0]
X_sample = np.array(X_sample).reshape(1,-1)

print(gbr.predict(X_sample)[0])  # 555315.2295879041

# confirm value of GBR
out_sum = 0
for t in range(50):
    estimator = gbr.estimators_[t,0]  # this is a regressor so there is only one output hence the 0
    value_in_decision_tree = estimator.predict(X_sample)[0]
    out_sum += .1*value_in_decision_tree  # 0.1 = learning rate
print(out_sum)  # 15227.087821374536

如果相关的话,我正在使用的数据。但我肯定我只是误解了这里的计算,所以我希望有人能帮助我解决问题。我想GBR从损失函数确定的基础预测中学习残差,所以我上面计算的两个值都是正确的,
求和对应于预测残值。本例中的原始初始预测为540088.14176653,由以下公式确定:

print(gbr.loss_.get_init_raw_predictions(
                X_sample, 
                gbr.init_).astype(np.float64))
我从
BaseGradientBoosting
\u raw\u predict\u init
方法中复制了这一点