onnxmltools
onnxmltools copied to clipboard
Feature Request: XGBoost: XGBClassifier with gblinear booster converts to onnx
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: https://github.com/onnx/onnxmltools/issues/609
Thank you in advance!