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

Feature Request: XGBoost: XGBClassifier with gblinear booster converts to onnx #628

Open
ahallermed opened this issue May 30, 2023 · 0 comments

Comments

@ahallermed
Copy link

Hello everyone,

I would like to convert my XGBClassifier with the 'gblinear' booster to onnx. Currently, this only works if the booster is 'gbtree'.
Because the gblinear doesn't use trees as weak learners, there is no tree node available.

The simplest example which fails would be:

from onnxmltools import convert_xgboost
from skl2onnx.common.data_types import FloatTensorType
from xgboost.sklearn import XGBClassifier

initial_type = [('float_input', FloatTensorType([None, 2]))]
model = XGBClassifier(booster="gblinear", random_state=42)
model.fit([[1, 2], [3, 4], [1, 2], [1, 2]], [1, 0, 0, 1])

convert_xgboost(model=model, initial_types=initial_type)

With this KeyError:

/onnxmltools/convert/xgboost/operator_converters/XGBoost.py:149), in XGBConverter._remap_nodeid(jsnode, remap)
python3.8/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py?line=146) if remap is None:
python3.8/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py?line=147)     remap = {}
python3.8/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py?line=148) nid = jsnode['nodeid']
python3.8/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py?line=149) remap[nid] = len(remap)
    [151](python3.8/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py?line=150) if 'children' in jsnode:

KeyError: 'nodeid'

Where the jsnode is:

{
  'bias': [7.8149, 1.98696, -3.35406],
  'weight': [0.471003, 0.150544, -0.370348, 2.27629, 0.182475, -0.925965, -2.71426, -0.322671, 0.544406, -12.1686, -1.75817, 2.87433]
}

For 'gbtree' everything works fine.

Related issues: #609

Thank you in advance!

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