Skip to content

Commit 59148c7

Browse files
committed
use self.datasets.full_data_dict, resolve pr comments
1 parent 65baf78 commit 59148c7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,16 @@ def _fallback_build_model(self):
336336
date_column = self.spec.datetime_column.name
337337
dataset = self.datasets
338338

339-
full_data_dict = dataset.full_data_dict
340-
341339
anomaly_output = AnomalyOutput(date_column=date_column)
342340

343341
# map the output as per anomaly dataset class, 1: outlier, 0: inlier
344-
outlier_map = {1: 0, -1: 1}
342+
self.outlier_map = {1: 0, -1: 1}
345343

346344
# Iterate over the full_data_dict items
347-
for target, df in full_data_dict.items():
345+
for target, df in self.datasets.full_data_dict.items():
348346
est = linear_model.SGDOneClassSVM(random_state=42)
349347
est.fit(df[target].values.reshape(-1, 1))
350-
y_pred = np.vectorize(outlier_map.get)(est.predict(df[target].values.reshape(-1, 1)))
348+
y_pred = np.vectorize(self.outlier_map.get)(est.predict(df[target].values.reshape(-1, 1)))
351349
scores = est.score_samples(df[target].values.reshape(-1, 1))
352350

353351
anomaly = pd.DataFrame({
@@ -356,7 +354,7 @@ def _fallback_build_model(self):
356354
}).reset_index(drop=True)
357355
score = pd.DataFrame({
358356
date_column: df[date_column],
359-
OutputColumns.SCORE_COL: [item for item in scores]
357+
OutputColumns.SCORE_COL: scores
360358
}).reset_index(drop=True)
361359
anomaly_output.add_output(target, anomaly, score)
362360

0 commit comments

Comments
 (0)