Closed pengcao closed 2 years ago
I train the model have the error [tweedie]: at least one target label is negative
Thanks for using LightGBM!
The tweedie distribution is only defined for 0s and positive numbers. This is why negative numbers in the target are not allowed. If you want to use that objective and have negative numbers in your target, consider converting your target like this:
y = y + abs(min(y))
If that doesn't work for you, please provide the information that was asked for in the issue template, including a reproducible example that we can run and an explanation of how LightGBM's behavior differs from what you expected.
Quick question - are you using Bonsai or Treesnip to train your LightGBM model?
I encountered a similar problem as well and opened up an issue on the Bonsai Github.
This issue has been automatically closed because it has been awaiting a response for too long. When you have time to to work with the maintainers to resolve this issue, please post a new comment and it will be re-opened. If the issue has been locked for editing by the time you return to it, please open a new issue and reference this one. Thank you for taking the time to improve LightGBM!
Hi, I am getting the same error when using tweedie as an objective: "at least one target label is negative" I made sure that my target variable has all its values positive but still I get the same error. Could anyone help?
I am using below packages with version: lightgbm==3.1.1 hyperopt==0.2.7 sklearn-pandas==2.2.0 category_encoders==2.6.0 holidays==0.11.2 mlflow==2.2.2 install pandas==1.2.4
Error trace: File "/databricks/python_shell/dbruntime/MLWorkloadsInstrumentation/_sklearn.py", line 29, in patch_function original_result = original(self, args, kwargs) File "/local_disk0/.ephemeral_nfs/envs/pythonEnv-e6a44093-7f23-41f7-90d6-08f637bea202/lib/python3.8/site-packages/sklearn/compose/target.py", line 246, in fit self.regressor.fit(X, y_trans, fit_params) File "/local_disk0/.ephemeral_nfs/envs/pythonEnv-e6a44093-7f23-41f7-90d6-08f637bea202/lib/python3.8/site-packages/mlflow/utils/autologging_utils/safety.py", line 434, in safe_patch_function return original(args, kwargs) File "/databricks/python/lib/python3.8/site-packages/lightgbm/sklearn.py", line 770, in fit super(LGBMRegressor, self).fit(X, y, sample_weight=sample_weight, File "/local_disk0/.ephemeral_nfs/envs/pythonEnv-e6a44093-7f23-41f7-90d6-08f637bea202/lib/python3.8/site-packages/mlflow/utils/autologging_utils/safety.py", line 434, in safe_patch_function return original(*args, *kwargs) File "/databricks/python/lib/python3.8/site-packages/lightgbm/sklearn.py", line 612, in fit self._Booster = train(params, train_set, File "/local_disk0/.ephemeral_nfs/envs/pythonEnv-e6a44093-7f23-41f7-90d6-08f637bea202/lib/python3.8/site-packages/mlflow/utils/autologging_utils/safety.py", line 434, in safe_patch_function return original(args, kwargs) File "/databricks/python/lib/python3.8/site-packages/lightgbm/engine.py", line 231, in train booster = Booster(params=params, train_set=train_set) File "/databricks/python/lib/python3.8/site-packages/lightgbm/basic.py", line 2058, in init _safe_call(_LIB.LGBM_BoosterCreate( File "/databricks/python/lib/python3.8/site-packages/lightgbm/basic.py", line 55, in _safe_call raise LightGBMError(decode_string(_LIB.LGBM_GetLastError())) lightgbm.basic.LightGBMError: [tweedie]: at least one target label is negative
warnings.warn(some_fits_failed_message, FitFailedWarning)
FYI: @jameslamb @pengcao @cbecker @kant
when initialize lightgbm, if your label has negative values. Don't use parameter 'objective' and named: 'tweedie'. Instead of 'regression'. https://www.geekmu.com/d/120-lightgbm
This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.
Description
Reproducible example
Environment info
LightGBM version or commit hash:
Command(s) you used to install LightGBM
Additional Comments