diff --git a/ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py b/ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py index 212a2a8c2..f1ea87738 100644 --- a/ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py +++ b/ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py @@ -1,11 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*-- # Copyright (c) 2023, 2024 Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ import importlib -from collections import defaultdict import numpy as np import pandas as pd @@ -100,20 +98,24 @@ def _build_model(self) -> AnomalyOutput: for model_name, (model_config, model) in model_config_map.items(): model_config = model_config(**self.spec.model_kwargs) if hasattr(model_config, "target_seq_index"): - model_config.target_seq_index = df.columns.get_loc(self.spec.target_column) + model_config.target_seq_index = df.columns.get_loc( + self.spec.target_column + ) model = model(model_config) - scores = model.train(train_data=data, anomaly_labels=None) try: y_pred = model.get_anomaly_label(data) - y_pred =(y_pred.to_pd().reset_index()["anom_score"] > 0).astype(int) + y_pred = ( + y_pred.to_pd().reset_index()["anom_score"] > 0 + ).astype(int) except Exception as e: y_pred = ( scores.to_pd().reset_index()["anom_score"] > np.percentile( - scores.to_pd().reset_index()["anom_score"], anomaly_threshold + scores.to_pd().reset_index()["anom_score"], + anomaly_threshold, ) ).astype(int) diff --git a/tests/operators/anomaly/test_anomaly_simple.py b/tests/operators/anomaly/test_anomaly_simple.py index 20e392aa2..6d3e7daea 100644 --- a/tests/operators/anomaly/test_anomaly_simple.py +++ b/tests/operators/anomaly/test_anomaly_simple.py @@ -54,6 +54,7 @@ MODELS = ["autots", "oneclasssvm", "isolationforest", "randomcutforest"] + @pytest.mark.parametrize("model", ["autots", "merlion_ad"]) def test_artificial_big(model): all_data = []