开启掘金成长之旅!这是我参与「掘金日新计划 · 2 月更文挑战」的第 12 天,点击查看活动详情
不是一个参数,loss是损失函数,能绝对建模的方向,就像伪残差就是通过loss推导出来的,criterion是分枝参数
loss: {‘squared_error’, ‘absolute_error’, ‘huber’, ‘quantile’}, default=’squared_error’ Loss function to be optimized. ‘squared_error’ refers to the squared error for regression. ‘absolute_error’ refers to the absolute error of regression and is a robust loss function. ‘huber’ is a combination of the two. ‘quantile’ allows quantile regression (use
alpha
to specify the quantile). 被优化的损失函数。‘squared_error’指的是回归的平方损失。‘absolute_error’指的是回归的绝对损失。‘huber’是二者的结合。‘quantile’使用分位数回归(使用alpha
来指定分位数)criterion: {‘friedman_mse’, ‘squared_error’}, default=’friedman_mse’ The function to measure the quality of a split. Supported criteria are “friedman_mse” for the mean squared error with improvement score by Friedman, “squared_error” for mean squared error. The default value of “friedman_mse” is generally the best as it can provide a better approximation in some cases. 衡量分枝质量的函数。支持的分枝标准有 Friedman 所使用的 “friedman_mse”搭配均方误差作为优化函数,“squared_error”搭配均方误差。“friedman_mse”的默认值通常是最好的,因为它在某些情况下可以提供更好的近似值
loss 决定了建模的对象,伪残差就是由 loss 为平方误差所计算出来的,criterion 决定了建树的标准
先看代码
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.datasets import load_boston
reg = GradientBoostingRegressor(learning_rate=0.3,n_estimators=5 ,max_depth=None
,criterion='mae' ,loss='squared_error' )
reg.fit(X,y)
reg.score(X,y)
---
0.9717524751
reg = GradientBoostingRegressor(learning_rate=0.3,n_estimators=5 ,max_depth=None
,loss='squared_error')
reg.fit(X,y)
reg.score(X,y)
---
0.9717524751
先设置 loss 为 squared_error,criterion 为 mae,然后设置 loss 为 squared_error,criterion 为默认是也就是 friedman_mse,此时我们得到的模型得分是相同的,注意,这是回归数据,因此这不是巧合,猜测二者都表示分枝标准,且如果在模型中同时指明了 loss 和 criterion,则 loss 优先度大于 criterion,如果只指明一个,则使用该参数
reg = GradientBoostingRegressor(learning_rate=0.3,n_estimators=5 ,max_depth=None
,loss='absolute_error')
reg.fit(X,y)
reg.score(X,y)
---
0.8063985934919977
并且,如果我们只使用 criterion,并指明其为 mae(或者 mse),会报一个警告
reg = GradientBoostingRegressor(learning_rate=0.3,n_estimators=5 ,max_depth=None
,criterion='mae' )
reg.fit(X,y)
FutureWarning: criterion='mae' was deprecated in version 0.24 and will be removed in version 1.1 (renaming of 0.26). The correct way of minimizing the absolute error is to use loss='absolute_error' instead. FutureWarning:criterion='mae'在0.24版本中已经被弃用,在1.1版本中将会被移除。最小化绝对损失的方式是使用loss='absolute_error'来代替
这也证明了 loss 和 criterion 是同一个对象
以下与loss和criterion无关,凑个字数
sklearn GradientBoosting 中 init 参数的解释
GradientBoostingClassifier 中的 init
init: estimator or ‘zero’, default=None init:评估器或'zero',默认值=None
An estimator object that is used to compute the initial predictions. init has to provide fit and predict_proba. If ‘zero’, the initial raw predictions are set to zero. By default, a DummyEstimator predicting the classes priors is used. 使用评估器对象计算初始预测值。init 需要提供 fit 和 predict_proba。如果选择‘zero’,初始预测值为 0 。默认情况下,使用 DummyEstimator 预测类的先验
GradientBoostingRegressor 中的 init
init: estimator or ‘zero’, default=None init:评估器或'zero',默认值=None
An estimator object that is used to compute the initial predictions. init has to provide fit and predict. If ‘zero’, the initial raw predictions are set to zero. By default a DummyEstimator is used, predicting either the average target value (for loss=’squared_error’), or a quantile for the other losses. 使用评估器对象计算初始预测值。init 需要提供 fit 和 predict。如果选择‘zero’,初始预测值为 0 。默认情况下,使用 DummyEstimator,预测为平均标签值(对于损失函数为’squared_error’的情况下),或者其他损失函数的分位数