Skip to content

Commit 2e53e12

Browse files
committed
organize imports, fix format, missing commas
1 parent 19269a3 commit 2e53e12

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
from ads.common.decorator.runtime_dependency import runtime_dependency
8+
from ads.opctl import logger
89
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
10+
11+
from ..const import SupportedModels
912
from .anomaly_dataset import AnomalyOutput
1013
from .base_model import AnomalyOperatorBaseModel
11-
from ..const import SupportedModels
12-
from ads.opctl import logger
1314

1415

1516
class AutoTSOperatorModel(AnomalyOperatorBaseModel):
1617
"""Class representing AutoTS Anomaly Detection operator model."""
18+
1719
model_mapping = {
1820
"isolationforest": "IsolationForest",
1921
"lof": "LOF",
@@ -22,30 +24,43 @@ class AutoTSOperatorModel(AnomalyOperatorBaseModel):
2224
"rolling_zscore": "rolling_zscore",
2325
"mad": "mad",
2426
"minmax": "minmax",
25-
"iqr": "IQR"
27+
"iqr": "IQR",
2628
}
2729

2830
@runtime_dependency(
2931
module="autots",
3032
err_msg=(
31-
"Please run `pip3 install autots` to "
32-
"install the required dependencies for AutoTS."
33+
"Please run `pip3 install autots` to "
34+
"install the required dependencies for AutoTS."
3335
),
3436
)
3537
def _build_model(self) -> AnomalyOutput:
3638
from autots.evaluator.anomaly_detector import AnomalyDetector
3739

38-
method = SupportedModels.ISOLATIONFOREST if self.spec.model == SupportedModels.AutoTS else self.spec.model
39-
model_params = {"method": self.model_mapping[method],
40-
"transform_dict": self.spec.model_kwargs.get("transform_dict", {}),
41-
"output": self.spec.model_kwargs.get("output", "univariate"), "method_params": {}}
40+
method = (
41+
SupportedModels.ISOLATIONFOREST
42+
if self.spec.model == SupportedModels.AutoTS
43+
else self.spec.model
44+
)
45+
model_params = {
46+
"method": self.model_mapping[method],
47+
"transform_dict": self.spec.model_kwargs.get("transform_dict", {}),
48+
"output": self.spec.model_kwargs.get("output", "univariate"),
49+
"method_params": {},
50+
}
4251
# Supported methods with contamination param
43-
if method in [SupportedModels.ISOLATIONFOREST, SupportedModels.LOF, SupportedModels.EE]:
44-
model_params["method_params"][
45-
"contamination"] = self.spec.contamination if self.spec.contamination else 0.01
46-
else:
47-
if self.spec.contamination:
48-
raise ValueError(f"The contamination parameter is not supported for the selected model \"{method}\"")
52+
if method in [
53+
SupportedModels.ISOLATIONFOREST,
54+
SupportedModels.LOF,
55+
SupportedModels.EE,
56+
]:
57+
model_params["method_params"]["contamination"] = (
58+
self.spec.contamination if self.spec.contamination else 0.01
59+
)
60+
elif self.spec.contamination:
61+
raise ValueError(
62+
f'The contamination parameter is not supported for the selected model "{method}"'
63+
)
4964
logger.info(f"model params: {model_params}")
5065

5166
model = AnomalyDetector(**model_params)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

66
from ads.opctl.operator.lowcode.anomaly.utils import select_auto_model
7+
8+
from ..const import NonTimeADSupportedModels, SupportedModels
9+
from ..operator_config import AnomalyOperatorConfig
710
from .anomaly_dataset import AnomalyDatasets
811
from .anomaly_merlion import AnomalyMerlionOperatorModel
912
from .autots import AutoTSOperatorModel
1013
from .base_model import AnomalyOperatorBaseModel
1114
from .isolationforest import IsolationForestOperatorModel
1215
from .oneclasssvm import OneClassSVMOperatorModel
1316
from .randomcutforest import RandomCutForestOperatorModel
14-
from ..const import NonTimeADSupportedModels, SupportedModels
15-
from ..operator_config import AnomalyOperatorConfig
1617

1718

1819
class UnSupportedModelError(Exception):
@@ -49,8 +50,8 @@ class AnomalyOperatorModelFactory:
4950
SupportedModels.ZSCORE: AutoTSOperatorModel,
5051
SupportedModels.ROLLING_ZSCORE: AutoTSOperatorModel,
5152
SupportedModels.EE: AutoTSOperatorModel,
52-
SupportedModels.MAD: AutoTSOperatorModel
53-
SupportedModels.MerilonAD: AnomalyMerlionOperatorModel
53+
SupportedModels.MAD: AutoTSOperatorModel,
54+
SupportedModels.MerilonAD: AnomalyMerlionOperatorModel,
5455
}
5556

5657
_NonTime_MAP = {

0 commit comments

Comments
 (0)