[英]LightGBM predicts negative values
My LightGBM regressor model returns negative values.我的LightGBM 回归量 model 返回负值。
For XGBoost there is objective='count:poisson' hyperparameter in order to prevent returning negative predicitons.对于XGBoost ,有objective='count:poisson'超参数以防止返回负预测。
Is there any chance to do this?有机会这样做吗?
Github issue => https://github.com/microsoft/LightGBM/issues/5629 Github 问题 => https://github.com/microsoft/LightGBM/issues/5629
LightGBM also supports poisson regression. LightGBM 还支持泊松回归。 For example, consider the following Python code.例如,考虑以下 Python 代码。
import lightgbm as lgb
import numpy as np
from matplotlib import pyplot
# random Poisson-distributed target and one informative feature
y = np.random.poisson(lam=15.0, size=1_000)
X = y + np.random.normal(loc=10.0, scale=2.0, size=(y.shape[0], ))
X = X.reshape(-1, 1)
# fit a Poisson regression model
reg = lgb.LGBMRegressor(
objective="poisson",
n_estimators=150,
min_data=1
)
reg.fit(X, y)
# get predictions
preds = reg.predict(X)
print("summary of predicted values")
print(f" * min: {round(np.min(preds), 3)}")
print(f" * max: {round(np.max(preds), 3)}")
# compare predicted distribution to the empirical one
bins = np.linspace(0, 30, 50)
pyplot.hist(y, bins, alpha=0.5, label='actual')
pyplot.hist(preds, bins, alpha=0.5, label='predicted')
pyplot.legend(loc='upper right')
pyplot.show()
This example uses Python 3.10 and lightgbm==3.3.3
.此示例使用 Python 3.10 和lightgbm==3.3.3
。
However... I don't recommend using Poisson regression just to achieve "no negative predictions".但是......我不建议仅仅为了实现“无负面预测”而使用泊松回归。 The Poisson loss function is intended to be used for cases where you believe your target is Poisson-distributed, eg it looks like counts of events observed over some regular interval like time or space.泊松损失 function 旨在用于您认为目标服从泊松分布的情况,例如,它看起来像是在某个固定时间间隔(如时间或空间)内观察到的事件计数。
Other options you might consider to try to achieve the behavior "never predict a negative number from LightGBM regression":您可能会考虑尝试实现“从不从 LightGBM 回归中预测负数”行为的其他选项:
LightGBM also facilitates an objective
parameter which can be set to 'poisson'
. LightGBM 还促进了可以设置为'poisson'
的objective
参数。 Follow this link for more information. 点击此链接了解更多信息。
An example for LGBMRegressor
(scikit-learn API): LGBMRegressor
(scikit-learn API)的一个例子:
from lightgbm import LGBMRegressor
regressor = LGBMRegressor(objective='poisson')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.