oracle-ads 2.12.5__py3-none-any.whl → 2.12.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ads/aqua/common/decorator.py +10 -0
- ads/aqua/common/utils.py +4 -1
- ads/aqua/constants.py +1 -0
- ads/aqua/evaluation/entities.py +14 -4
- ads/aqua/evaluation/evaluation.py +2 -6
- ads/aqua/extension/aqua_ws_msg_handler.py +2 -0
- ads/aqua/extension/base_handler.py +2 -0
- ads/aqua/extension/model_handler.py +4 -0
- ads/aqua/finetuning/constants.py +3 -0
- ads/aqua/finetuning/finetuning.py +13 -2
- ads/aqua/model/entities.py +2 -0
- ads/aqua/model/model.py +25 -19
- ads/llm/autogen/__init__.py +0 -0
- ads/llm/autogen/client_v02.py +282 -0
- ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py +6 -5
- ads/opctl/operator/lowcode/anomaly/model/automlx.py +12 -8
- ads/opctl/operator/lowcode/anomaly/model/autots.py +6 -3
- ads/opctl/operator/lowcode/anomaly/model/base_model.py +19 -7
- ads/opctl/operator/lowcode/anomaly/model/isolationforest.py +9 -10
- ads/opctl/operator/lowcode/anomaly/model/oneclasssvm.py +10 -11
- ads/opctl/operator/lowcode/anomaly/model/randomcutforest.py +6 -2
- ads/opctl/operator/lowcode/common/data.py +13 -11
- ads/opctl/operator/lowcode/forecast/model/arima.py +14 -12
- ads/opctl/operator/lowcode/forecast/model/automlx.py +26 -26
- ads/opctl/operator/lowcode/forecast/model/autots.py +16 -18
- ads/opctl/operator/lowcode/forecast/model/base_model.py +45 -36
- ads/opctl/operator/lowcode/forecast/model/forecast_datasets.py +36 -47
- ads/opctl/operator/lowcode/forecast/model/ml_forecast.py +3 -0
- ads/opctl/operator/lowcode/forecast/model/neuralprophet.py +30 -46
- ads/opctl/operator/lowcode/forecast/model/prophet.py +15 -20
- ads/opctl/operator/lowcode/forecast/model_evaluator.py +25 -20
- ads/opctl/operator/lowcode/forecast/utils.py +30 -33
- ads/opctl/operator/lowcode/pii/model/report.py +11 -7
- ads/opctl/operator/lowcode/recommender/model/base_model.py +58 -45
- ads/opctl/operator/lowcode/recommender/model/svd.py +47 -29
- {oracle_ads-2.12.5.dist-info → oracle_ads-2.12.7.dist-info}/METADATA +7 -6
- {oracle_ads-2.12.5.dist-info → oracle_ads-2.12.7.dist-info}/RECORD +40 -38
- {oracle_ads-2.12.5.dist-info → oracle_ads-2.12.7.dist-info}/LICENSE.txt +0 -0
- {oracle_ads-2.12.5.dist-info → oracle_ads-2.12.7.dist-info}/WHEEL +0 -0
- {oracle_ads-2.12.5.dist-info → oracle_ads-2.12.7.dist-info}/entry_points.txt +0 -0
@@ -4,9 +4,11 @@
|
|
4
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
5
|
|
6
6
|
import importlib
|
7
|
+
import logging
|
7
8
|
|
8
9
|
import numpy as np
|
9
10
|
import pandas as pd
|
11
|
+
import report_creator as rc
|
10
12
|
from merlion.post_process.threshold import AggregateAlarms
|
11
13
|
from merlion.utils import TimeSeries
|
12
14
|
|
@@ -21,6 +23,8 @@ from ads.opctl.operator.lowcode.anomaly.const import (
|
|
21
23
|
from .anomaly_dataset import AnomalyOutput
|
22
24
|
from .base_model import AnomalyOperatorBaseModel
|
23
25
|
|
26
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
27
|
+
|
24
28
|
|
25
29
|
class AnomalyMerlionOperatorModel(AnomalyOperatorBaseModel):
|
26
30
|
"""Class representing Merlion Anomaly Detection operator model."""
|
@@ -84,7 +88,7 @@ class AnomalyMerlionOperatorModel(AnomalyOperatorBaseModel):
|
|
84
88
|
for target, df in self.datasets.full_data_dict.items():
|
85
89
|
data = df.set_index(date_column)
|
86
90
|
data = TimeSeries.from_pd(data)
|
87
|
-
for
|
91
|
+
for _, (model_config, model) in model_config_map.items():
|
88
92
|
if self.spec.model == SupportedModels.BOCPD:
|
89
93
|
model_config = model_config(**self.spec.model_kwargs)
|
90
94
|
else:
|
@@ -115,7 +119,7 @@ class AnomalyMerlionOperatorModel(AnomalyOperatorBaseModel):
|
|
115
119
|
y_pred = (y_pred.to_pd().reset_index()["anom_score"] > 0).astype(
|
116
120
|
int
|
117
121
|
)
|
118
|
-
except Exception
|
122
|
+
except Exception:
|
119
123
|
y_pred = (
|
120
124
|
scores["anom_score"]
|
121
125
|
> np.percentile(
|
@@ -135,15 +139,12 @@ class AnomalyMerlionOperatorModel(AnomalyOperatorBaseModel):
|
|
135
139
|
OutputColumns.SCORE_COL: scores["anom_score"],
|
136
140
|
}
|
137
141
|
).reset_index(drop=True)
|
138
|
-
# model_objects[model_name].append(model)
|
139
142
|
|
140
143
|
anomaly_output.add_output(target, anomaly, score)
|
141
144
|
return anomaly_output
|
142
145
|
|
143
146
|
def _generate_report(self):
|
144
147
|
"""Genreates a report for the model."""
|
145
|
-
import report_creator as rc
|
146
|
-
|
147
148
|
other_sections = [
|
148
149
|
rc.Heading("Selected Models Overview", level=2),
|
149
150
|
rc.Text(
|
@@ -1,16 +1,21 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
6
|
+
import logging
|
7
|
+
|
7
8
|
import pandas as pd
|
9
|
+
import report_creator as rc
|
8
10
|
|
9
11
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
10
|
-
from .
|
12
|
+
from ads.opctl import logger
|
13
|
+
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
|
11
14
|
|
15
|
+
from .anomaly_dataset import AnomalyOutput
|
12
16
|
from .base_model import AnomalyOperatorBaseModel
|
13
|
-
|
17
|
+
|
18
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
14
19
|
|
15
20
|
|
16
21
|
class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
|
@@ -25,16 +30,17 @@ class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
|
|
25
30
|
),
|
26
31
|
)
|
27
32
|
def _build_model(self) -> pd.DataFrame:
|
28
|
-
from automlx import init
|
29
33
|
import logging
|
30
34
|
|
35
|
+
import automlx
|
36
|
+
|
31
37
|
try:
|
32
|
-
init(
|
38
|
+
automlx.init(
|
33
39
|
engine="ray",
|
34
40
|
engine_opts={"ray_setup": {"_temp_dir": "/tmp/ray-temp"}},
|
35
41
|
loglevel=logging.CRITICAL,
|
36
42
|
)
|
37
|
-
except Exception
|
43
|
+
except Exception:
|
38
44
|
logger.info("Ray already initialized")
|
39
45
|
date_column = self.spec.datetime_column.name
|
40
46
|
anomaly_output = AnomalyOutput(date_column=date_column)
|
@@ -73,8 +79,6 @@ class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
|
|
73
79
|
return anomaly_output
|
74
80
|
|
75
81
|
def _generate_report(self):
|
76
|
-
import report_creator as rc
|
77
|
-
|
78
82
|
"""The method that needs to be implemented on the particular model level."""
|
79
83
|
other_sections = [
|
80
84
|
rc.Heading("Selected Models Overview", level=2),
|
@@ -1,9 +1,12 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
6
|
+
import logging
|
7
|
+
|
8
|
+
import report_creator as rc
|
9
|
+
|
7
10
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
8
11
|
from ads.opctl import logger
|
9
12
|
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
|
@@ -12,6 +15,8 @@ from ..const import SupportedModels
|
|
12
15
|
from .anomaly_dataset import AnomalyOutput
|
13
16
|
from .base_model import AnomalyOperatorBaseModel
|
14
17
|
|
18
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
19
|
+
|
15
20
|
|
16
21
|
class AutoTSOperatorModel(AnomalyOperatorBaseModel):
|
17
22
|
"""Class representing AutoTS Anomaly Detection operator model."""
|
@@ -91,8 +96,6 @@ class AutoTSOperatorModel(AnomalyOperatorBaseModel):
|
|
91
96
|
return anomaly_output
|
92
97
|
|
93
98
|
def _generate_report(self):
|
94
|
-
import report_creator as rc
|
95
|
-
|
96
99
|
"""The method that needs to be implemented on the particular model level."""
|
97
100
|
other_sections = [
|
98
101
|
rc.Heading("Selected Models Overview", level=2),
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
4
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
5
|
|
6
|
+
import logging
|
6
7
|
import os
|
7
8
|
import tempfile
|
8
9
|
import time
|
@@ -12,6 +13,7 @@ from typing import Tuple
|
|
12
13
|
import fsspec
|
13
14
|
import numpy as np
|
14
15
|
import pandas as pd
|
16
|
+
import report_creator as rc
|
15
17
|
from sklearn import linear_model
|
16
18
|
|
17
19
|
from ads.common.object_storage_details import ObjectStorageDetails
|
@@ -33,6 +35,8 @@ from ..const import NonTimeADSupportedModels, SupportedModels
|
|
33
35
|
from ..operator_config import AnomalyOperatorConfig, AnomalyOperatorSpec
|
34
36
|
from .anomaly_dataset import AnomalyDatasets, AnomalyOutput, TestData
|
35
37
|
|
38
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
39
|
+
|
36
40
|
|
37
41
|
class AnomalyOperatorBaseModel(ABC):
|
38
42
|
"""The base class for the anomaly detection operator models."""
|
@@ -59,8 +63,8 @@ class AnomalyOperatorBaseModel(ABC):
|
|
59
63
|
def generate_report(self):
|
60
64
|
"""Generates the report."""
|
61
65
|
import matplotlib.pyplot as plt
|
62
|
-
|
63
|
-
|
66
|
+
|
67
|
+
plt.rcParams.update({"figure.max_open_warning": 0})
|
64
68
|
|
65
69
|
start_time = time.time()
|
66
70
|
# fallback using sklearn oneclasssvm when the sub model _build_model fails
|
@@ -84,7 +88,13 @@ class AnomalyOperatorBaseModel(ABC):
|
|
84
88
|
anomaly_output, test_data, elapsed_time
|
85
89
|
)
|
86
90
|
table_blocks = [
|
87
|
-
rc.DataTable(
|
91
|
+
rc.DataTable(
|
92
|
+
df.head(SUBSAMPLE_THRESHOLD)
|
93
|
+
if self.spec.subsample_report_data and len(df) > SUBSAMPLE_THRESHOLD
|
94
|
+
else df,
|
95
|
+
label=col,
|
96
|
+
index=True,
|
97
|
+
)
|
88
98
|
for col, df in self.datasets.full_data_dict.items()
|
89
99
|
]
|
90
100
|
data_table = rc.Select(blocks=table_blocks)
|
@@ -144,7 +154,9 @@ class AnomalyOperatorBaseModel(ABC):
|
|
144
154
|
else:
|
145
155
|
figure_blocks = None
|
146
156
|
|
147
|
-
blocks.append(
|
157
|
+
blocks.append(
|
158
|
+
rc.Group(*figure_blocks, label=target)
|
159
|
+
) if figure_blocks else None
|
148
160
|
plots = rc.Select(blocks)
|
149
161
|
|
150
162
|
report_sections = []
|
@@ -154,7 +166,9 @@ class AnomalyOperatorBaseModel(ABC):
|
|
154
166
|
yaml_appendix = rc.Yaml(self.config.to_dict())
|
155
167
|
summary = rc.Block(
|
156
168
|
rc.Group(
|
157
|
-
rc.Text(
|
169
|
+
rc.Text(
|
170
|
+
f"You selected the **`{self.spec.model}`** model.\n{model_description.text}\n"
|
171
|
+
),
|
158
172
|
rc.Text(
|
159
173
|
"Based on your dataset, you could have also selected "
|
160
174
|
f"any of the models: `{'`, `'.join(SupportedModels.keys() if self.spec.datetime_column else NonTimeADSupportedModels.keys())}`."
|
@@ -285,8 +299,6 @@ class AnomalyOperatorBaseModel(ABC):
|
|
285
299
|
test_metrics: pd.DataFrame,
|
286
300
|
):
|
287
301
|
"""Saves resulting reports to the given folder."""
|
288
|
-
import report_creator as rc
|
289
|
-
|
290
302
|
unique_output_dir = self.spec.output_directory.url
|
291
303
|
|
292
304
|
if ObjectStorageDetails.is_oci_path(unique_output_dir):
|
@@ -1,17 +1,21 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
6
|
+
import logging
|
7
|
+
|
7
8
|
import numpy as np
|
8
9
|
import pandas as pd
|
10
|
+
import report_creator as rc
|
9
11
|
|
10
12
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
13
|
+
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
|
11
14
|
|
12
|
-
from .base_model import AnomalyOperatorBaseModel
|
13
15
|
from .anomaly_dataset import AnomalyOutput
|
14
|
-
from
|
16
|
+
from .base_model import AnomalyOperatorBaseModel
|
17
|
+
|
18
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
15
19
|
|
16
20
|
|
17
21
|
class IsolationForestOperatorModel(AnomalyOperatorBaseModel):
|
@@ -36,13 +40,9 @@ class IsolationForestOperatorModel(AnomalyOperatorBaseModel):
|
|
36
40
|
for target, df in self.datasets.full_data_dict.items():
|
37
41
|
model = IsolationForest(**model_kwargs)
|
38
42
|
model.fit(df)
|
39
|
-
y_pred = np.vectorize(self.outlier_map.get)(
|
40
|
-
model.predict(df)
|
41
|
-
)
|
43
|
+
y_pred = np.vectorize(self.outlier_map.get)(model.predict(df))
|
42
44
|
|
43
|
-
scores = model.score_samples(
|
44
|
-
df
|
45
|
-
)
|
45
|
+
scores = model.score_samples(df)
|
46
46
|
|
47
47
|
index_col = df.columns[0]
|
48
48
|
|
@@ -59,7 +59,6 @@ class IsolationForestOperatorModel(AnomalyOperatorBaseModel):
|
|
59
59
|
|
60
60
|
def _generate_report(self):
|
61
61
|
"""Generates the report."""
|
62
|
-
import report_creator as rc
|
63
62
|
|
64
63
|
other_sections = [
|
65
64
|
rc.Heading("Selected Models Overview", level=2),
|
@@ -1,17 +1,21 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
6
|
+
import logging
|
7
|
+
|
7
8
|
import numpy as np
|
8
9
|
import pandas as pd
|
10
|
+
import report_creator as rc
|
9
11
|
|
10
12
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
13
|
+
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
|
11
14
|
|
12
|
-
from .base_model import AnomalyOperatorBaseModel
|
13
15
|
from .anomaly_dataset import AnomalyOutput
|
14
|
-
from
|
16
|
+
from .base_model import AnomalyOperatorBaseModel
|
17
|
+
|
18
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
15
19
|
|
16
20
|
|
17
21
|
class OneClassSVMOperatorModel(AnomalyOperatorBaseModel):
|
@@ -36,13 +40,9 @@ class OneClassSVMOperatorModel(AnomalyOperatorBaseModel):
|
|
36
40
|
for target, df in self.datasets.full_data_dict.items():
|
37
41
|
model = OneClassSVM(**model_kwargs)
|
38
42
|
model.fit(df)
|
39
|
-
y_pred = np.vectorize(self.outlier_map.get)(
|
40
|
-
model.predict(df)
|
41
|
-
)
|
43
|
+
y_pred = np.vectorize(self.outlier_map.get)(model.predict(df))
|
42
44
|
|
43
|
-
scores = model.score_samples(
|
44
|
-
df
|
45
|
-
)
|
45
|
+
scores = model.score_samples(df)
|
46
46
|
|
47
47
|
index_col = df.columns[0]
|
48
48
|
|
@@ -54,12 +54,11 @@ class OneClassSVMOperatorModel(AnomalyOperatorBaseModel):
|
|
54
54
|
).reset_index(drop=True)
|
55
55
|
|
56
56
|
anomaly_output.add_output(target, anomaly, score)
|
57
|
-
|
57
|
+
|
58
58
|
return anomaly_output
|
59
59
|
|
60
60
|
def _generate_report(self):
|
61
61
|
"""Generates the report."""
|
62
|
-
import report_creator as rc
|
63
62
|
|
64
63
|
other_sections = [
|
65
64
|
rc.Heading("Selected Models Overview", level=2),
|
@@ -3,8 +3,11 @@
|
|
3
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
4
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
5
|
|
6
|
+
import logging
|
7
|
+
|
6
8
|
import numpy as np
|
7
9
|
import pandas as pd
|
10
|
+
import report_creator as rc
|
8
11
|
|
9
12
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
10
13
|
from ads.opctl import logger
|
@@ -13,6 +16,8 @@ from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
|
|
13
16
|
from .anomaly_dataset import AnomalyOutput
|
14
17
|
from .base_model import AnomalyOperatorBaseModel
|
15
18
|
|
19
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
20
|
+
|
16
21
|
|
17
22
|
class RandomCutForestOperatorModel(AnomalyOperatorBaseModel):
|
18
23
|
"""
|
@@ -27,7 +32,7 @@ class RandomCutForestOperatorModel(AnomalyOperatorBaseModel):
|
|
27
32
|
),
|
28
33
|
)
|
29
34
|
def _build_model(self) -> AnomalyOutput:
|
30
|
-
|
35
|
+
import rrcf
|
31
36
|
|
32
37
|
model_kwargs = self.spec.model_kwargs
|
33
38
|
|
@@ -96,7 +101,6 @@ class RandomCutForestOperatorModel(AnomalyOperatorBaseModel):
|
|
96
101
|
|
97
102
|
def _generate_report(self):
|
98
103
|
"""Generates the report."""
|
99
|
-
import report_creator as rc
|
100
104
|
|
101
105
|
other_sections = [
|
102
106
|
rc.Heading("Selected Models Overview", level=2),
|
@@ -1,22 +1,21 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
7
6
|
import time
|
8
|
-
from
|
7
|
+
from abc import ABC
|
8
|
+
|
9
|
+
import pandas as pd
|
10
|
+
|
9
11
|
from ads.opctl import logger
|
10
12
|
from ads.opctl.operator.lowcode.common.const import DataColumns
|
11
|
-
from ads.opctl.operator.lowcode.common.utils import load_data
|
12
13
|
from ads.opctl.operator.lowcode.common.errors import (
|
13
|
-
InputDataError,
|
14
14
|
InvalidParameterError,
|
15
|
-
PermissionsError,
|
16
|
-
DataMismatchError,
|
17
15
|
)
|
18
|
-
from
|
19
|
-
|
16
|
+
from ads.opctl.operator.lowcode.common.utils import load_data
|
17
|
+
|
18
|
+
from .transformations import Transformations
|
20
19
|
|
21
20
|
|
22
21
|
class AbstractData(ABC):
|
@@ -35,12 +34,15 @@ class AbstractData(ABC):
|
|
35
34
|
condition = pd.Series(True, index=self.raw_data.index)
|
36
35
|
if category in mapping:
|
37
36
|
for col, val in mapping[category].items():
|
38
|
-
condition &=
|
37
|
+
condition &= self.raw_data[col] == val
|
39
38
|
data_by_cat = self.raw_data[condition].reset_index(drop=True)
|
40
|
-
data_by_cat =
|
39
|
+
data_by_cat = (
|
40
|
+
self._data_transformer._format_datetime_col(data_by_cat)
|
41
|
+
if self.spec.datetime_column
|
42
|
+
else data_by_cat
|
43
|
+
)
|
41
44
|
return data_by_cat
|
42
45
|
|
43
|
-
|
44
46
|
def get_dict_by_series(self):
|
45
47
|
if not self._data_dict:
|
46
48
|
for s_id in self.list_series_ids():
|
@@ -1,23 +1,26 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
5
|
|
6
|
+
import logging
|
7
|
+
import traceback
|
8
|
+
|
7
9
|
import pandas as pd
|
8
|
-
import numpy as np
|
9
10
|
import pmdarima as pm
|
11
|
+
import report_creator as rc
|
10
12
|
from joblib import Parallel, delayed
|
11
13
|
|
12
14
|
from ads.opctl import logger
|
13
|
-
|
14
|
-
from ads.opctl.operator.lowcode.forecast.utils import _label_encode_dataframe
|
15
15
|
from ads.opctl.operator.lowcode.common.utils import seconds_to_datetime
|
16
|
-
from .
|
16
|
+
from ads.opctl.operator.lowcode.forecast.utils import _label_encode_dataframe
|
17
|
+
|
18
|
+
from ..const import ForecastOutputColumns, SupportedModels
|
17
19
|
from ..operator_config import ForecastOperatorConfig
|
18
|
-
import
|
20
|
+
from .base_model import ForecastOperatorBaseModel
|
19
21
|
from .forecast_datasets import ForecastDatasets, ForecastOutput
|
20
|
-
|
22
|
+
|
23
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
21
24
|
|
22
25
|
|
23
26
|
class ArimaOperatorModel(ForecastOperatorBaseModel):
|
@@ -39,7 +42,7 @@ class ArimaOperatorModel(ForecastOperatorBaseModel):
|
|
39
42
|
)
|
40
43
|
model_kwargs = self.spec.model_kwargs
|
41
44
|
model_kwargs["alpha"] = 1 - self.spec.confidence_interval_width
|
42
|
-
if "error_action" not in model_kwargs
|
45
|
+
if "error_action" not in model_kwargs:
|
43
46
|
model_kwargs["error_action"] = "ignore"
|
44
47
|
return model_kwargs
|
45
48
|
|
@@ -129,13 +132,14 @@ class ArimaOperatorModel(ForecastOperatorBaseModel):
|
|
129
132
|
self.errors_dict[s_id] = {
|
130
133
|
"model_name": self.spec.model,
|
131
134
|
"error": str(e),
|
132
|
-
"error_trace": traceback.format_exc()
|
135
|
+
"error_trace": traceback.format_exc(),
|
136
|
+
}
|
133
137
|
logger.warn(f"Encountered Error: {e}. Skipping.")
|
134
138
|
logger.warn(traceback.format_exc())
|
135
139
|
|
136
140
|
def _build_model(self) -> pd.DataFrame:
|
137
141
|
full_data_dict = self.datasets.get_data_by_series()
|
138
|
-
self.models =
|
142
|
+
self.models = {}
|
139
143
|
self.additional_regressors = self.datasets.get_additional_data_column_names()
|
140
144
|
model_kwargs = self.set_kwargs()
|
141
145
|
self.forecast_output = ForecastOutput(
|
@@ -154,8 +158,6 @@ class ArimaOperatorModel(ForecastOperatorBaseModel):
|
|
154
158
|
|
155
159
|
def _generate_report(self):
|
156
160
|
"""The method that needs to be implemented on the particular model level."""
|
157
|
-
import report_creator as rc
|
158
|
-
|
159
161
|
all_sections = []
|
160
162
|
if len(self.models) > 0:
|
161
163
|
sec5_text = rc.Heading("ARIMA Model Parameters", level=2)
|
@@ -1,29 +1,30 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
|
-
import traceback
|
4
|
-
|
5
2
|
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
|
6
3
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
4
|
+
import logging
|
5
|
+
import traceback
|
7
6
|
|
8
|
-
import pandas as pd
|
9
7
|
import numpy as np
|
8
|
+
import pandas as pd
|
9
|
+
import report_creator as rc
|
10
|
+
|
10
11
|
from ads.common.decorator.runtime_dependency import runtime_dependency
|
12
|
+
from ads.opctl import logger
|
13
|
+
from ads.opctl.operator.lowcode.common.utils import (
|
14
|
+
seconds_to_datetime,
|
15
|
+
)
|
11
16
|
from ads.opctl.operator.lowcode.forecast.const import (
|
12
17
|
AUTOMLX_METRIC_MAP,
|
13
18
|
ForecastOutputColumns,
|
14
19
|
SupportedModels,
|
15
20
|
)
|
16
|
-
from ads.opctl import
|
21
|
+
from ads.opctl.operator.lowcode.forecast.utils import _label_encode_dataframe
|
17
22
|
|
18
|
-
from .base_model import ForecastOperatorBaseModel
|
19
23
|
from ..operator_config import ForecastOperatorConfig
|
24
|
+
from .base_model import ForecastOperatorBaseModel
|
20
25
|
from .forecast_datasets import ForecastDatasets, ForecastOutput
|
21
|
-
from ads.opctl.operator.lowcode.common.utils import (
|
22
|
-
seconds_to_datetime,
|
23
|
-
datetime_to_seconds,
|
24
|
-
)
|
25
|
-
from ads.opctl.operator.lowcode.forecast.utils import _label_encode_dataframe
|
26
26
|
|
27
|
+
logging.getLogger("report_creator").setLevel(logging.WARNING)
|
27
28
|
AUTOMLX_N_ALGOS_TUNED = 4
|
28
29
|
AUTOMLX_DEFAULT_SCORE_METRIC = "neg_sym_mean_abs_percent_error"
|
29
30
|
|
@@ -47,12 +48,13 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
47
48
|
)
|
48
49
|
model_kwargs_cleaned.pop("task", None)
|
49
50
|
time_budget = model_kwargs_cleaned.pop("time_budget", -1)
|
50
|
-
model_kwargs_cleaned[
|
51
|
-
|
52
|
-
|
51
|
+
model_kwargs_cleaned["preprocessing"] = (
|
52
|
+
self.spec.preprocessing.enabled
|
53
|
+
or model_kwargs_cleaned.get("preprocessing", True)
|
54
|
+
)
|
53
55
|
return model_kwargs_cleaned, time_budget
|
54
56
|
|
55
|
-
def preprocess(self, data
|
57
|
+
def preprocess(self, data): # TODO: re-use self.le for explanations
|
56
58
|
_, df_encoded = _label_encode_dataframe(
|
57
59
|
data,
|
58
60
|
no_encode={self.spec.datetime_column.name, self.original_target_column},
|
@@ -74,9 +76,10 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
74
76
|
),
|
75
77
|
)
|
76
78
|
def _build_model(self) -> pd.DataFrame:
|
77
|
-
from automlx import init
|
78
79
|
import logging
|
79
80
|
|
81
|
+
from automlx import Pipeline, init
|
82
|
+
|
80
83
|
try:
|
81
84
|
init(
|
82
85
|
engine="ray",
|
@@ -88,7 +91,7 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
88
91
|
|
89
92
|
full_data_dict = self.datasets.get_data_by_series()
|
90
93
|
|
91
|
-
self.models =
|
94
|
+
self.models = {}
|
92
95
|
horizon = self.spec.horizon
|
93
96
|
self.spec.confidence_interval_width = self.spec.confidence_interval_width or 0.8
|
94
97
|
self.forecast_output = ForecastOutput(
|
@@ -101,7 +104,7 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
101
104
|
# Clean up kwargs for pass through
|
102
105
|
model_kwargs_cleaned, time_budget = self.set_kwargs()
|
103
106
|
|
104
|
-
for
|
107
|
+
for s_id, df in full_data_dict.items():
|
105
108
|
try:
|
106
109
|
logger.debug(f"Running automlx on series {s_id}")
|
107
110
|
model_kwargs = model_kwargs_cleaned.copy()
|
@@ -120,7 +123,7 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
120
123
|
if self.loaded_models is not None and s_id in self.loaded_models:
|
121
124
|
model = self.loaded_models[s_id]
|
122
125
|
else:
|
123
|
-
model =
|
126
|
+
model = Pipeline(
|
124
127
|
task="forecasting",
|
125
128
|
**model_kwargs,
|
126
129
|
)
|
@@ -170,7 +173,7 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
170
173
|
self.errors_dict[s_id] = {
|
171
174
|
"model_name": self.spec.model,
|
172
175
|
"error": str(e),
|
173
|
-
"error_trace": traceback.format_exc()
|
176
|
+
"error_trace": traceback.format_exc(),
|
174
177
|
}
|
175
178
|
logger.warn(f"Encountered Error: {e}. Skipping.")
|
176
179
|
logger.warn(traceback.format_exc())
|
@@ -197,15 +200,12 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
197
200
|
- ds_forecast_col (pd.Series): The pd.Series object representing the forecasted column.
|
198
201
|
- ci_col_names (List[str]): A list of column names for the confidence interval in the report.
|
199
202
|
"""
|
200
|
-
|
201
|
-
|
202
|
-
"""The method that needs to be implemented on the particular model level."""
|
203
|
-
selected_models = dict()
|
203
|
+
selected_models = {}
|
204
204
|
models = self.models
|
205
205
|
other_sections = []
|
206
206
|
|
207
207
|
if len(self.models) > 0:
|
208
|
-
for
|
208
|
+
for s_id, m in models.items():
|
209
209
|
selected_models[s_id] = {
|
210
210
|
"series_id": s_id,
|
211
211
|
"selected_model": m.selected_model_,
|
@@ -352,7 +352,7 @@ class AutoMLXOperatorModel(ForecastOperatorBaseModel):
|
|
352
352
|
"""
|
353
353
|
data_temp = pd.DataFrame(
|
354
354
|
data,
|
355
|
-
columns=
|
355
|
+
columns=list(self.dataset_cols),
|
356
356
|
)
|
357
357
|
|
358
358
|
return self.models.get(self.series_id).forecast(
|