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

Convert_xgboost for XGBRegressor with objective="reg:logistic" gives wrong results #646

Open
laurentbeaughon opened this issue Aug 18, 2023 · 0 comments

Comments

@laurentbeaughon
Copy link

laurentbeaughon commented Aug 18, 2023

When converting a XGBRegressor with objective="reg:logistic", the onnx model and the XGBoost model give different results.

The difference seems to be a sigmoid transformation that is not included in the model.

Here is a script to reproduce:

import numpy as np

from onnxmltools import convert_xgboost
from skl2onnx.common.data_types import FloatTensorType

X_train = np.random.rand(20, 10).astype(np.float32)
Y_train = np.random.randint(2, size=20)
X_test = np.random.rand(1, 10).astype(np.float32)

xg_reg = XGBRegressor(objective="reg:logistic").fit(X_train, Y_train)
xg_pred = xg_reg.predict(X_test)
xgb_onnx = convert_xgboost(xg_reg, initial_types=[("float_input", FloatTensorType([None, 10]))])

import onnxruntime
onx_reg = onnxruntime.InferenceSession(xgb_onnx.SerializeToString())
onnx_pred = onx_reg.run(None, {"float_input": X_test})


print(f"xgboost prediction: {xg_pred}")
print(f"onnx prediction: {onnx_pred}")

onnx_pred_fixed = 1 / (np.exp(-onnx_pred[0] + 0.5) + 1)

print(f"onnx prediction fixed: {onnx_pred_fixed}")
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