Skip to content

[ENH] implemented anomaly detection _fit_predict override output checks #2818

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions aeon/testing/estimator_checking/_yield_anomaly_detection_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,33 @@ def check_anomaly_detector_output(estimator, datatype):
), "y_pred must contain only 0s, 1s, True, or False"
else:
raise ValueError(f"Unknown anomaly output type: {ot}")


def check_anomaly_detector_fit_predict(estimator, datatype):
"""Test the anomaly detector fit_predict method."""
est1 = _clone_estimator(estimator)
est2 = _clone_estimator(estimator)
estimator_class = type(estimator)

# Doesn't proceed if _fit_predict is inherited
if "_fit_predict" not in estimator_class.__dict__:
return

fit_predict_output = est1.fit_predict(
FULL_TEST_DATA_DICT[datatype]["train"][0],
FULL_TEST_DATA_DICT[datatype]["train"][1],
)
assert isinstance(fit_predict_output, np.ndarray)

expected_output = est2.fit(
FULL_TEST_DATA_DICT[datatype]["train"][0],
FULL_TEST_DATA_DICT[datatype]["train"][1],
).predict(FULL_TEST_DATA_DICT[datatype]["train"][0])

assert isinstance(expected_output, np.ndarray)

# Assert outputs are same
assert len(fit_predict_output) == len(expected_output)
assert np.array_equal(
fit_predict_output, expected_output
), "outputs of _fit_predict() does not match fit().predict()"