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

Fixed GradientBoostingRegression model conversion failure with init=zero #164

Merged
15 changes: 9 additions & 6 deletions skl2onnx/operator_converters/gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ def convert_sklearn_gradient_boosting_regressor(scope, operator, container):
attrs['name'] = scope.get_unique_operator_name(op_type)
attrs['n_targets'] = 1

# constant_ was introduced in scikit-learn 0.21.
if hasattr(op.init_, 'constant_'):
cst = [float(x) for x in op.init_.constant_]
elif op.loss == 'ls':
cst = [op.init_.mean]
if op.init_ == 'zero':
cst = np.zeros((operator.inputs[0].type.shape[0], op.loss_.K))
else:
cst = [op.init_.quantile]
# constant_ was introduced in scikit-learn 0.21.
if hasattr(op.init_, 'constant_'):
cst = [float(x) for x in op.init_.constant_]
elif op.loss == 'ls':
cst = [op.init_.mean]
else:
cst = [op.init_.quantile]
attrs['base_values'] = [float(x) for x in cst]

tree_weight = op.learning_rate
Expand Down