Skip to content

Commit

Permalink
format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
codeloop committed Sep 30, 2024
1 parent 7468503 commit 4679082
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tests/operators/anomaly/test_anomaly_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

MODELS = ["autots", "oneclasssvm", "isolationforest", "randomcutforest"]


@pytest.mark.parametrize("model", ["autots", "merlion_ad"])
def test_artificial_big(model):
all_data = []
Expand Down

0 comments on commit 4679082

Please sign in to comment.