Skip to content

Commit 129c0d8

Browse files
committed
autots bug
1 parent 72e4586 commit 129c0d8

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

ads/opctl/operator/lowcode/anomaly/MLoperator

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ keywords:
77
- Anomaly Detection
88
backends:
99
- job
10+
- operator.local
1011
description: |
1112
Anomaly Detection is the identification of rare items, events, or observations in data that
1213
differ significantly from the expectation. This can be used for several scenarios like asset

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
import yaml
1212

1313
from ads.opctl import logger
14-
from ads.opctl.operator.lowcode.common.utils import (
15-
disable_print,
16-
enable_print,
17-
seconds_to_datetime,
18-
)
14+
from ads.opctl.operator.lowcode.common.utils import seconds_to_datetime
1915
from .base_model import ForecastOperatorBaseModel
2016
from ..operator_config import ForecastOperatorConfig
2117
from ads.common.decorator.runtime_dependency import runtime_dependency
@@ -124,21 +120,29 @@ def _build_model(self) -> pd.DataFrame:
124120
full_data_indexed = self.datasets.get_data_multi_indexed()
125121

126122
dates = full_data_indexed.index.get_level_values(0).unique().tolist()
127-
horizon_idx = dates[-self.spec.horizon :]
128123
train_idx = dates[: -self.spec.horizon]
129124

130-
regr_fcst = full_data_indexed[
131-
full_data_indexed.index.get_level_values(0).isin(horizon_idx)
132-
].reset_index()
133-
regr_train = full_data_indexed[
125+
df_train = full_data_indexed[
134126
full_data_indexed.index.get_level_values(0).isin(train_idx)
135-
]
136-
self.future_regressor_train = regr_train.copy()
127+
][[self.original_target_column]].reset_index()
128+
129+
# Future regressors need to be in wide format - (num_unique_dates x (num_unique_series x num_unique_cols))
130+
additional_regressors = list(
131+
set(full_data_indexed.columns) - {self.original_target_column}
132+
)
133+
future_regressor = full_data_indexed.reset_index().pivot(
134+
index=self.spec.datetime_column.name,
135+
columns=ForecastOutputColumns.SERIES,
136+
values=additional_regressors,
137+
)
138+
139+
future_reg = future_regressor[: -self.spec.horizon]
140+
regr_fcst = future_regressor[-self.spec.horizon :]
137141

138142
if self.loaded_models is None:
139143
model = model.fit(
140-
full_data_indexed.reset_index(),
141-
future_regressor=regr_train.reset_index(),
144+
df_train,
145+
future_regressor=future_reg,
142146
date_col=self.spec.datetime_column.name,
143147
value_col=self.original_target_column,
144148
id_col=ForecastOutputColumns.SERIES,

tests/operators/anomaly/test_anomaly_simple.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
import os
1414
import numpy as np
15+
from datetime import datetime
1516
from ads.opctl.operator.cmd import run
1617

1718

@@ -79,7 +80,7 @@ def test_artificial_big(model):
7980
with tempfile.TemporaryDirectory() as tmpdirname:
8081
anomaly_yaml_filename = f"{tmpdirname}/anomaly.yaml"
8182
input_data = f"{tmpdirname}/data.csv"
82-
output_dirname = f"{tmpdirname}/results"
83+
output_dirname = f"{tmpdirname}/results_{datetime.now()}"
8384

8485
d.to_csv(input_data, index=False)
8586

@@ -121,7 +122,7 @@ def test_artificial_small(model):
121122
with tempfile.TemporaryDirectory() as tmpdirname:
122123
anomaly_yaml_filename = f"{tmpdirname}/anomaly.yaml"
123124
input_data = f"{tmpdirname}/data.csv"
124-
output_dirname = f"{tmpdirname}/results"
125+
output_dirname = f"{tmpdirname}/results_{datetime.now()}"
125126

126127
d.to_csv(input_data, index=False)
127128

@@ -170,7 +171,7 @@ def test_validation(model):
170171
input_data = f"{tmpdirname}/data.csv"
171172
valid_data = f"{tmpdirname}/valid_data.csv"
172173
test_data = f"{tmpdirname}/test_data.csv"
173-
output_dirname = f"{tmpdirname}/results"
174+
output_dirname = f"{tmpdirname}/results_{datetime.now()}"
174175

175176
d.to_csv(input_data, index=False)
176177
v.to_csv(valid_data, index=False)
@@ -201,7 +202,7 @@ def test_validation(model):
201202
def test_load_datasets(model, data_dict):
202203
with tempfile.TemporaryDirectory() as tmpdirname:
203204
anomaly_yaml_filename = f"{tmpdirname}/anomaly.yaml"
204-
output_dirname = f"{tmpdirname}/results"
205+
output_dirname = f"{tmpdirname}/results_{datetime.now()}"
205206

206207
yaml_i = deepcopy(TEMPLATE_YAML)
207208
yaml_i["spec"]["model"] = model
@@ -225,9 +226,3 @@ def test_load_datasets(model, data_dict):
225226
# oultiers = pd.read_csv(f"{output_dirname}/anomaly.csv")
226227
# print(oultiers)
227228
assert os.path.exists(f"{output_dirname}/report.html"), "Report not generated."
228-
229-
# if TEMPLATE_YAML["spec"]["generate_explanations"]:
230-
# glb_expl = pd.read_csv(f"{tmpdirname}/results/global_explanation.csv")
231-
# print(glb_expl)
232-
# loc_expl = pd.read_csv(f"{tmpdirname}/results/local_explanation.csv")
233-
# print(loc_expl)

0 commit comments

Comments
 (0)