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

OrdinalEncoder handle encoded_missing_value and unknown_value #1132

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

LLukas22
Copy link
Contributor

In the current version of sklearn-onnx, the encoded_missing_value and unknown_value parameters of the OrdinalEncoder in scikit-learn are not properly handled. Specifically, these parameters are ignored during the ONNX model conversion.

For example, if we create an OrdinalEncoder with encoded_missing_value set to 42 and fit it on the following data: np.array([["a"], ["b"], ["c"], ["d"], [np.nan]], dtype=np.object_), scikit-learn produces the expected output: [0, 1, 2, 3, 42]. However, the converted ONNX model does not respect the encoded_missing_value parameter, leading to an unexpected result: [0, 1, 2, 3, 4].

Similarly, the unknown_value parameter is also ignored during conversion, which affects the expected output. To address this issue, the default_int64 parameter of the ONNX LabelEncoder needs to be set when an unknown_value is specified.

I have included some tests to demonstrate this behavior and implemented a simple fix to resolve the issue.

tests/test_sklearn_ordinal_encoder.py Fixed Show fixed Hide fixed
tests/test_sklearn_ordinal_encoder.py Fixed Show fixed Hide fixed
tests/test_sklearn_ordinal_encoder.py Fixed Show fixed Hide fixed
@LLukas22 LLukas22 force-pushed the ordinal_encoded_missing_value branch from efc8da3 to 4c23ba8 Compare November 14, 2024 11:11
LLukas22 and others added 3 commits November 14, 2024 14:27
Signed-off-by: Lukas Kreussel <[email protected]>
Signed-off-by: Lukas Kreussel <[email protected]>
@LLukas22 LLukas22 force-pushed the ordinal_encoded_missing_value branch from 4c23ba8 to e7e8996 Compare November 14, 2024 13:28
Signed-off-by: Lukas Kreussel <[email protected]>
@LLukas22
Copy link
Contributor Author

Re-signed my commits, this should be good to go now 👍

@xadupre xadupre merged commit c672994 into onnx:main Nov 14, 2024
20 checks passed
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

Successfully merging this pull request may close these issues.

2 participants