Fix sigmoid calibration for Pipeline-wrapped estimators#1247
Open
huntermills707 wants to merge 1 commit intoonnx:mainfrom
Open
Fix sigmoid calibration for Pipeline-wrapped estimators#1247huntermills707 wants to merge 1 commit intoonnx:mainfrom
huntermills707 wants to merge 1 commit intoonnx:mainfrom
Conversation
…teps This change ensures that if the `raw_scores` option is set for a Pipeline, it is correctly passed down to its constituent classifiers or sub-pipelines. This is particularly important for models like `CalibratedClassifierCV` when they wrap a Pipeline, as they might rely on raw scores for calibration. - Updated `skl2onnx/operator_converters/pipelines.py` to check for and propagate the `raw_scores` option. - Added a regression test in `tests/test_sklearn_calibrated_classifier_cv_converter.py` verifying `CalibratedClassifierCV` functionality when using a Pipeline as the base estimator. Signed-off-by: Hunter Mills <hunter.mills@pm.me>
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.
Fix sigmoid calibration for Pipeline-wrapped estimators
Fixes #1246
Problem
When
CalibratedClassifierCV(method='sigmoid')wraps aPipeline, the ONNX export produces incorrect probabilities. Theraw_scoresoption is set on the Pipeline by the calibrated classifier converter, but the Pipeline converter never propagates it to the inner classifier. The sigmoid calibrationexpit(-(a*x + b))is then applied to probability outputs instead of raw decision function scores.Fix
Propagate
raw_scoresfrom the Pipeline to its classifier steps inconvert_pipeline(skl2onnx/operator_converters/pipelines.py). The pattern for reading and forwardingraw_scoresto sub-estimators was mimicked fromskl2onnx/operator_converters/bagging.py(lines 30–32).Changes
skl2onnx/operator_converters/pipelines.py: Read the Pipeline'sraw_scoresoption and forward it to classifier steps that support it.tests/test_sklearn_calibrated_classifier_cv_converter.py: Addtest_model_calibrated_classifier_cv_sigmoid_pipelinecovering bothensemble=Trueandensemble=False.Verification
Reproducer output after fix:
No regressions in existing pipeline or calibrated classifier tests.