5
5
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
7
7
from ads .common .decorator .runtime_dependency import runtime_dependency
8
+ from ads .opctl import logger
8
9
from ads .opctl .operator .lowcode .anomaly .const import OutputColumns
10
+
11
+ from ..const import SupportedModels
9
12
from .anomaly_dataset import AnomalyOutput
10
13
from .base_model import AnomalyOperatorBaseModel
11
- from ..const import SupportedModels
12
- from ads .opctl import logger
13
14
14
15
15
16
class AutoTSOperatorModel (AnomalyOperatorBaseModel ):
16
17
"""Class representing AutoTS Anomaly Detection operator model."""
18
+
17
19
model_mapping = {
18
20
"isolationforest" : "IsolationForest" ,
19
21
"lof" : "LOF" ,
@@ -22,30 +24,43 @@ class AutoTSOperatorModel(AnomalyOperatorBaseModel):
22
24
"rolling_zscore" : "rolling_zscore" ,
23
25
"mad" : "mad" ,
24
26
"minmax" : "minmax" ,
25
- "iqr" : "IQR"
27
+ "iqr" : "IQR" ,
26
28
}
27
29
28
30
@runtime_dependency (
29
31
module = "autots" ,
30
32
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."
33
35
),
34
36
)
35
37
def _build_model (self ) -> AnomalyOutput :
36
38
from autots .evaluator .anomaly_detector import AnomalyDetector
37
39
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
+ }
42
51
# 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
+ )
49
64
logger .info (f"model params: { model_params } " )
50
65
51
66
model = AnomalyDetector (** model_params )
0 commit comments