-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add adapters to address output conversion for OfflineDetector. #34662
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
Add adapters to address output conversion for OfflineDetector. #34662
Conversation
7bf6a54
to
979fa37
Compare
10cb58b
to
6525546
Compare
The failed coverage tests are unrelated to this PR. |
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - could we make the error a little clearer? Otherwise LGTM
assert isinstance(prediction, AnomalyPrediction), ( | ||
"Wrong model handler output type." + | ||
f"Expected: 'AnomalyPrediction', but got '{type(prediction).__name__}'. " + # pylint: disable=line-too-long | ||
"Consider adding a post-processing function via `with_postprocess_fn`.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Consider adding a post-processing function via `with_postprocess_fn`.") | |
"Consider adding a post-processing function via `with_postprocess_fn`" + | |
"to convert from '{type(prediction).__name__}' to 'AnomalyPrediction', or " + | |
"use `score_prediction_adapter` or `label_prediction_adapter` to " + | |
"perform the conversion.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Assigning reviewers. If you would like to opt out of this review, comment R: @tvalentyn for label python. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Previously,
OfflineDetector
assumed that user-provided model handlers would output floating-point score values. This assumption often doesn't hold, particularly for third-party anomaly detection models (like PyOD's) that output labels instead of scores.This PR addresses this by making the output type generic (using a type variable). It also introduces common adapters to convert
RunInference
predictions into theAnomalyPrediction
format. This approach improves ease-of-use for common scenarios while preserving flexibility for future extensions.