Skip to content

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

Merged
merged 3 commits into from
Apr 22, 2025

Conversation

shunping
Copy link
Collaborator

@shunping shunping commented Apr 18, 2025

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 the AnomalyPrediction format. This approach improves ease-of-use for common scenarios while preserving flexibility for future extensions.

@shunping shunping self-assigned this Apr 18, 2025
@shunping shunping force-pushed the anomaly-better-model-output-type branch from 7bf6a54 to 979fa37 Compare April 18, 2025 01:02
@shunping shunping force-pushed the anomaly-better-model-output-type branch from 10cb58b to 6525546 Compare April 18, 2025 02:26
@shunping shunping requested a review from damccorm April 18, 2025 03:13
@shunping
Copy link
Collaborator Author

The failed coverage tests are unrelated to this PR.

Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

Copy link
Contributor

@damccorm damccorm left a 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`.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @tvalentyn for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@liferoad liferoad merged commit c600069 into apache:master Apr 22, 2025
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants