Skip to content

Commit ddaeede

Browse files
committed
minor typo
1 parent c945550 commit ddaeede

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

ads/opctl/operator/lowcode/anomaly/__main__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

43
# Copyright (c) 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
@@ -15,7 +14,7 @@
1514
from ads.opctl.operator.common.const import ENV_OPERATOR_ARGS
1615
from ads.opctl.operator.common.utils import _parse_input_args
1716

18-
from .model.anomaly_dataset import AnomalyDatasets, AnomalyData
17+
from .model.anomaly_dataset import AnomalyDatasets
1918
from .operator_config import AnomalyOperatorConfig
2019

2120

@@ -34,7 +33,7 @@ def operate(operator_config: AnomalyOperatorConfig) -> None:
3433
f"Failed to forecast with error {e.args}. Trying again with model `autots`."
3534
)
3635
operator_config.spec.model = "autots"
37-
operator_config.spec.model_kwargs = dict()
36+
operator_config.spec.model_kwargs = {}
3837
datasets = AnomalyDatasets(operator_config.spec)
3938
try:
4039
AnomalyOperatorModelFactory.get_model(
@@ -44,12 +43,12 @@ def operate(operator_config: AnomalyOperatorConfig) -> None:
4443
logger.debug(
4544
f"Failed to backup forecast with error {ee.args}. Raising original error."
4645
)
47-
raise ee
46+
raise ee
4847
else:
4948
raise e
5049

5150

52-
def verify(spec: Dict, **kwargs: Dict) -> bool:
51+
def verify(spec: Dict) -> bool:
5352
"""Verifies the anomaly detection operator config."""
5453
operator = AnomalyOperatorConfig.from_dict(spec)
5554
msg_header = (
@@ -83,7 +82,7 @@ def main(raw_args: List[str]):
8382
yaml_string = yaml.safe_dump(json.loads(operator_spec_str))
8483
except json.JSONDecodeError:
8584
yaml_string = yaml.safe_dump(yaml.safe_load(operator_spec_str))
86-
except:
85+
except Exception:
8786
yaml_string = operator_spec_str
8887

8988
operator_config = AnomalyOperatorConfig.from_yaml(

ads/opctl/operator/lowcode/anomaly/model/factory.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
3+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

7-
from ..const import SupportedModels, NonTimeADSupportedModels
6+
from ads.opctl.operator.lowcode.anomaly.utils import select_auto_model
7+
8+
from ..const import NonTimeADSupportedModels, SupportedModels
89
from ..operator_config import AnomalyOperatorConfig
10+
from .anomaly_dataset import AnomalyDatasets
911
from .automlx import AutoMLXOperatorModel
1012
from .autots import AutoTSOperatorModel
11-
from .oneclasssvm import OneClassSVMOperatorModel
12-
from .isolationforest import IsolationForestOperatorModel
13-
from ads.opctl.operator.lowcode.anomaly.utils import select_auto_model
1413

1514
# from .tods import TODSOperatorModel
1615
from .base_model import AnomalyOperatorBaseModel
17-
from .anomaly_dataset import AnomalyDatasets
16+
from .isolationforest import IsolationForestOperatorModel
17+
from .oneclasssvm import OneClassSVMOperatorModel
1818

1919

2020
class UnSupportedModelError(Exception):
@@ -83,7 +83,7 @@ def get_model(
8383
"""
8484
model_type = operator_config.spec.model
8585
if model_type == "auto":
86-
model_type = select_auto_model(datasets, operator_config)
86+
model_type = select_auto_model(operator_config)
8787

8888
model_map = (
8989
cls._MAP if operator_config.spec.datetime_column else cls._NonTime_MAP

ads/opctl/operator/lowcode/anomaly/utils.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

43
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

76
import os
7+
88
import pandas as pd
9-
import fsspec
10-
from .operator_config import AnomalyOperatorSpec
11-
from .const import SupportedMetrics, SupportedModels
9+
1210
from ads.opctl import logger
1311

12+
from .const import SupportedMetrics, SupportedModels
13+
from .operator_config import AnomalyOperatorSpec
14+
1415

1516
def _build_metrics_df(y_true, y_pred, column_name):
1617
from sklearn.metrics import (
17-
recall_score,
18-
precision_score,
1918
accuracy_score,
20-
f1_score,
21-
confusion_matrix,
22-
roc_auc_score,
23-
precision_recall_curve,
2419
auc,
20+
confusion_matrix,
21+
f1_score,
2522
matthews_corrcoef,
23+
precision_recall_curve,
24+
precision_score,
25+
recall_score,
26+
roc_auc_score,
2627
)
2728

28-
metrics = dict()
29+
metrics = {}
2930
metrics[SupportedMetrics.RECALL] = recall_score(y_true, y_pred)
3031
metrics[SupportedMetrics.PRECISION] = precision_score(y_true, y_pred)
3132
metrics[SupportedMetrics.ACCURACY] = accuracy_score(y_true, y_pred)
@@ -78,5 +79,7 @@ def default_signer(**kwargs):
7879
return default_signer(**kwargs)
7980

8081

81-
def select_auto_model(datasets, operator_config):
82-
return SupportedModels.AutoTS
82+
def select_auto_model(operator_config):
83+
if operator_config.spec.datetime_column is not None:
84+
return SupportedModels.AutoTS
85+
return SupportedModels.IsolationForest

docs/source/user_guide/operators/anomaly_detection_operator/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Within the ``anomaly`` folder created above there will be a ``anomaly.yaml`` fil
4141
name: ds
4242
input_data:
4343
url: https://raw.githubusercontent.com/facebook/prophet/main/examples/example_yosemite_temps.csv
44-
model: automlx
44+
model: autots
4545
target_column: y
4646
4747
There are many more options in this :doc:`YAML file <./yaml_schema>`.

0 commit comments

Comments
 (0)