55# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
77from ads .common .decorator .runtime_dependency import runtime_dependency
8+ from ads .opctl import logger
89from ads .opctl .operator .lowcode .anomaly .const import OutputColumns
10+
11+ from ..const import SupportedModels
912from .anomaly_dataset import AnomalyOutput
1013from .base_model import AnomalyOperatorBaseModel
11- from ..const import SupportedModels
12- from ads .opctl import logger
1314
1415
1516class 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 )
0 commit comments