Fix xgboost categorical codes#773
Open
andife wants to merge 6 commits into
Open
Conversation
XGBoost stores category codes (0, 1, 2...) in its tree JSON dump for categorical splits. The ONNX converter builds BRANCH_EQ nodes that compare against those codes. However, the tests were passing the actual category values (e.g. 65, 66, 67 for 'A', 'B', 'C' after ord()) instead of the pandas category codes (0, 1, 2...). Since the values never matched any BRANCH_EQ split condition, all samples fell to the same default leaf, producing a constant ONNX output and causing assertions to fail with 100% element mismatch. Fix: use X["f0"].cat.codes instead of X[["f0"]].values in: - test_xgb_regressor_categorical_hist - test_xgb_regressor_categorical_hist_native - test_xgb_regressor_only_categorical_hist Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
LightGBM's predict_proba() with a custom objective returns raw scores (not probabilities) and emits a warning to that effect. Newer skl2onnx (installed alongside onnx>=1.18) correctly wraps binary classifier output with a sigmoid node, so the ONNX model produces probabilities while LightGBM produces raw scores — causing the assertion to fail. Fix: detect at runtime whether the ONNX output is probabilities (rows sum to 1) or raw scores, and apply scipy.special.expit (sigmoid) to the LightGBM raw scores before comparing in the probability case. This keeps backward compatibility with older skl2onnx where ONNX returns raw scores. Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.