Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported objective 'quantile' for LGBMRegressor #504

Closed
brunovilar opened this issue Oct 3, 2021 · 1 comment
Closed

Unsupported objective 'quantile' for LGBMRegressor #504

brunovilar opened this issue Oct 3, 2021 · 1 comment

Comments

@brunovilar
Copy link

brunovilar commented Oct 3, 2021

Issue description

When trying to run onnxmltools.convert_lightgbm on a lightgbm.sklearn.LGBMRegressor model with objective='poisson', the conversion fails with a RuntimeError.

Open PR

This is an update. O just saw this pull request. By directly applying the change it works properly. I would really recommend approving and merge the PR. :)

Similar closed issue

This problem seems to be similar to this one, reported by @janjagusch. I could not reproduce the workaround for the original (poisson) problem.

Reproducible example

import numpy as np
from lightgbm.sklearn import LGBMRegressor
from onnxmltools import convert_lightgbm
from skl2onnx.common.data_types import FloatTensorType

examples = 1000
features = 10

X = np.random.randn(examples, features)
y = np.round(np.random.randn(examples), 0)

model = LGBMRegressor(objective="quantile", metric="quantile", alpha=0.05)
model.fit(X, y)

initial_types = [("float_input", FloatTensorType([None, features]))]
onnx_model = convert_lightgbm(model, initial_types=initial_types)

Results in the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_33543/973951346.py in <module>
     14 
     15 initial_types = [("float_input", FloatTensorType([None, features]))]
---> 16 onnx_model = convert_lightgbm(model, initial_types=initial_types)

/media/bruno/dados/dev/virtual_envs/generic_env/lib/python3.9/site-packages/onnxmltools/convert/main.py in convert_lightgbm(model, name, initial_types, doc_string, target_opset, targeted_onnx, custom_conversion_functions, custom_shape_calculators, without_onnx_ml, zipmap)
    134 
    135     from .lightgbm.convert import convert
--> 136     return convert(model, name, initial_types, doc_string, target_opset, targeted_onnx,
    137                    custom_conversion_functions, custom_shape_calculators, without_onnx_ml,
    138                    zipmap=zipmap)

/media/bruno/dados/dev/virtual_envs/generic_env/lib/python3.9/site-packages/onnxmltools/convert/lightgbm/convert.py in convert(model, name, initial_types, doc_string, target_opset, targeted_onnx, custom_conversion_functions, custom_shape_calculators, without_onnx_ml, zipmap)
     54                               custom_shape_calculators, zipmap=zipmap)
     55     topology.compile()
---> 56     onnx_ml_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
     57 
     58     if without_onnx_ml:

/media/bruno/dados/dev/virtual_envs/generic_env/lib/python3.9/site-packages/onnxconverter_common/topology.py in convert_topology(topology, model_name, doc_string, target_opset, targeted_onnx, channel_first_inputs)
    774         else:
    775             # Convert the selected operator into some ONNX objects and save them into the container
--> 776             get_converter(operator.type)(scope, operator, container)
    777 
    778     # When calling ModelComponentContainer's add_initializer(...), nothing is added into the input list.

/media/bruno/dados/dev/virtual_envs/generic_env/lib/python3.9/site-packages/onnxmltools/convert/lightgbm/operator_converters/LightGbm.py in convert_lightgbm(scope, operator, container)
    398         post_transform = "Exp"
    399     else:
--> 400         raise RuntimeError(
    401             "LightGBM objective should be cleaned already not '{}'.".format(
    402                 gbm_text['objective']))

RuntimeError: LightGBM objective should be cleaned already not 'quantile'.

Versions

numpy==1.21.1
lightgbm==3.2.1
onnxmltools==1.9.1
skl2onnx==1.10.0
@brunovilar
Copy link
Author

As the PR was merged, this issue is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant