Skip to content

Commit f00f4e9

Browse files
committed
initial migration
1 parent e6da4bf commit f00f4e9

File tree

12 files changed

+383
-370
lines changed

12 files changed

+383
-370
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import pandas as pd
@@ -27,8 +27,13 @@ class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
2727
def _build_model(self) -> pd.DataFrame:
2828
from automlx import init
2929
import logging
30+
3031
try:
31-
init(engine="ray", engine_opts={"ray_setup": {"_temp_dir": "/tmp/ray-temp"}}, loglevel=logging.CRITICAL)
32+
init(
33+
engine="ray",
34+
engine_opts={"ray_setup": {"_temp_dir": "/tmp/ray-temp"}},
35+
loglevel=logging.CRITICAL,
36+
)
3237
except Exception as e:
3338
logger.info("Ray already initialized")
3439
date_column = self.spec.datetime_column.name
@@ -68,21 +73,21 @@ def _build_model(self) -> pd.DataFrame:
6873
return anomaly_output
6974

7075
def _generate_report(self):
71-
import datapane as dp
76+
import report_creator as rc
7277

7378
"""The method that needs to be implemented on the particular model level."""
74-
selected_models_text = dp.Text(
75-
f"## Selected Models Overview \n "
76-
"The following tables provide information regarding the chosen model."
77-
)
78-
all_sections = [selected_models_text]
79+
other_sections = [
80+
rc.Heading("Selected Models Overview", level=2),
81+
rc.Text(
82+
"The following tables provide information regarding the chosen model."
83+
),
84+
]
7985

80-
model_description = dp.Text(
86+
model_description = rc.Text(
8187
"The automlx model automatically pre-processes, selects and engineers "
8288
"high-quality features in your dataset, which then given to an automatically "
8389
"chosen and optimized machine learning model.."
8490
)
85-
other_sections = all_sections
8691

8792
return (
8893
model_description,

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import pandas as pd
@@ -81,21 +81,20 @@ def _build_model(self) -> AnomalyOutput:
8181
return anomaly_output
8282

8383
def _generate_report(self):
84-
import datapane as dp
84+
import report_creator as rc
8585

8686
"""The method that needs to be implemented on the particular model level."""
87-
selected_models_text = dp.Text(
88-
f"## Selected Models Overview \n "
89-
"The following tables provide information regarding the chosen model."
90-
)
91-
all_sections = [selected_models_text]
92-
93-
model_description = dp.Text(
87+
other_sections = [
88+
rc.Heading("Selected Models Overview", level=2),
89+
rc.Text(
90+
"The following tables provide information regarding the chosen model."
91+
),
92+
]
93+
model_description = rc.Text(
9494
"The automlx model automatically pre-processes, selects and engineers "
9595
"high-quality features in your dataset, which then given to an automatically "
9696
"chosen and optimized machine learning model.."
9797
)
98-
other_sections = all_sections
9998

10099
return (
101100
model_description,

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import os
@@ -57,7 +57,7 @@ def __init__(self, config: AnomalyOperatorConfig, datasets: AnomalyDatasets):
5757

5858
def generate_report(self):
5959
"""Generates the report."""
60-
import datapane as dp
60+
import report_creator as rc
6161
import matplotlib.pyplot as plt
6262

6363
start_time = time.time()
@@ -79,11 +79,11 @@ def generate_report(self):
7979
anomaly_output, test_data, elapsed_time
8080
)
8181
table_blocks = [
82-
dp.DataTable(df, label=col)
82+
rc.DataTable(df, label=col)
8383
for col, df in self.datasets.full_data_dict.items()
8484
]
8585
data_table = (
86-
dp.Select(blocks=table_blocks) if len(table_blocks) > 1 else table_blocks[0]
86+
rc.Select(blocks=table_blocks) if len(table_blocks) > 1 else table_blocks[0]
8787
)
8888
date_column = self.spec.datetime_column.name
8989

@@ -107,43 +107,43 @@ def generate_report(self):
107107
plt.ylabel(col)
108108
plt.title(f"`{col}` with reference to anomalies")
109109
figure_blocks.append(ax)
110-
blocks.append(dp.Group(blocks=figure_blocks, label=target))
111-
plots = dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
110+
blocks.append(rc.Group(blocks=figure_blocks, label=target))
111+
plots = rc.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
112112

113113
report_sections = []
114-
title_text = dp.Text("# Anomaly Detection Report")
114+
title_text = rc.Heading("Anomaly Detection Report", level=1)
115115

116-
yaml_appendix_title = dp.Text(f"## Reference: YAML File")
117-
yaml_appendix = dp.Code(code=self.config.to_yaml(), language="yaml")
118-
summary = dp.Blocks(
116+
yaml_appendix_title = rc.Heading("Reference: YAML File", level=2)
117+
yaml_appendix = rc.Code(code=self.config.to_yaml(), language="yaml")
118+
summary = rc.Blocks(
119119
blocks=[
120-
dp.Group(
121-
dp.Text(f"You selected the **`{self.spec.model}`** model."),
122-
dp.Text(
120+
rc.Group(
121+
rc.Text(f"You selected the **`{self.spec.model}`** model."),
122+
rc.Text(
123123
"Based on your dataset, you could have also selected "
124124
f"any of the models: `{'`, `'.join(SupportedModels.keys())}`."
125125
),
126-
dp.BigNumber(
126+
rc.BigNumber(
127127
heading="Analysis was completed in ",
128128
value=human_time_friendly(elapsed_time),
129129
),
130130
label="Summary",
131131
)
132132
]
133133
)
134-
sec_text = dp.Text(f"## Train Evaluation Metrics")
135-
sec = dp.DataTable(self._evaluation_metrics(anomaly_output))
134+
sec_text = rc.Heading("Train Evaluation Metrics", level=2)
135+
sec = rc.DataTable(self._evaluation_metrics(anomaly_output))
136136
evaluation_metrics_sec = [sec_text, sec]
137137

138138
test_metrics_sections = []
139139
if total_metrics is not None and not total_metrics.empty:
140-
sec_text = dp.Text(f"## Test Data Evaluation Metrics")
141-
sec = dp.DataTable(total_metrics)
140+
sec_text = rc.Heading("Test Data Evaluation Metrics", level=2)
141+
sec = rc.DataTable(total_metrics)
142142
test_metrics_sections = test_metrics_sections + [sec_text, sec]
143143

144144
if summary_metrics is not None and not summary_metrics.empty:
145-
sec_text = dp.Text(f"## Test Data Summary Metrics")
146-
sec = dp.DataTable(summary_metrics)
145+
sec_text = rc.Heading("Test Data Summary Metrics", level=2)
146+
sec = rc.DataTable(summary_metrics)
147147
test_metrics_sections = test_metrics_sections + [sec_text, sec]
148148

149149
report_sections = (
@@ -248,7 +248,7 @@ def _save_report(
248248
test_metrics: pd.DataFrame,
249249
):
250250
"""Saves resulting reports to the given folder."""
251-
import datapane as dp
251+
import report_creator as rc
252252

253253
unique_output_dir = find_output_dirname(self.spec.output_directory)
254254

@@ -261,7 +261,7 @@ def _save_report(
261261
with tempfile.TemporaryDirectory() as temp_dir:
262262
report_local_path = os.path.join(temp_dir, "___report.html")
263263
disable_print()
264-
dp.save_report(report_sections, report_local_path)
264+
rc.save_report(report_sections, report_local_path)
265265
enable_print()
266266
with open(report_local_path) as f1:
267267
with fsspec.open(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# #!/usr/bin/env python
22
# # -*- coding: utf-8 -*--
33

4-
# # Copyright (c) 2023 Oracle and/or its affiliates.
4+
# # Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
# import importlib
@@ -97,16 +97,16 @@
9797
# return anomaly_output
9898

9999
# def _generate_report(self):
100-
# import datapane as dp
100+
# import report_creator as rc
101101

102102
# """The method that needs to be implemented on the particular model level."""
103-
# selected_models_text = dp.Text(
103+
# selected_models_text = rc.Text(
104104
# f"## Selected Models Overview \n "
105105
# "The following tables provide information regarding the chosen model."
106106
# )
107107
# all_sections = [selected_models_text]
108108

109-
# model_description = dp.Text(
109+
# model_description = rc.Text(
110110
# "The tods model is a full-stack automated machine learning system for outlier detection "
111111
# "on univariate / multivariate time-series data. It provides exhaustive modules for building "
112112
# "machine learning-based outlier detection systems and wide range of algorithms."

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import pandas as pd
@@ -66,7 +66,7 @@ def _train_model(self, i, s_id, df, model_kwargs):
6666
target = self.original_target_column
6767
self.forecast_output.init_series_output(series_id=s_id, data_at_series=df)
6868
# If trend is constant, remove constant columns
69-
if 'trend' not in model_kwargs or model_kwargs['trend'] == 'c':
69+
if "trend" not in model_kwargs or model_kwargs["trend"] == "c":
7070
self.constant_cols[s_id] = df.columns[df.nunique() == 1]
7171
df = df.drop(columns=self.constant_cols[s_id])
7272

@@ -147,29 +147,25 @@ def _build_model(self) -> pd.DataFrame:
147147

148148
def _generate_report(self):
149149
"""The method that needs to be implemented on the particular model level."""
150-
import datapane as dp
150+
import report_creator as rc
151+
151152
all_sections = []
152153
if len(self.models) > 0:
153-
sec5_text = dp.Text(f"## ARIMA Model Parameters")
154+
sec5_text = rc.Heading("ARIMA Model Parameters", level=2)
154155
blocks = [
155-
dp.HTML(
156+
rc.Html(
156157
m.summary().as_html(),
157158
label=s_id,
158159
)
159160
for i, (s_id, m) in enumerate(self.models.items())
160161
]
161-
sec5 = dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
162+
sec5 = rc.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
162163
all_sections = [sec5_text, sec5]
163164

164165
if self.spec.generate_explanations:
165166
try:
166167
# If the key is present, call the "explain_model" method
167168
self.explain_model()
168-
# Create a markdown text block for the global explanation section
169-
global_explanation_text = dp.Text(
170-
f"## Global Explanation of Models \n "
171-
"The following tables provide the feature attribution for the global explainability."
172-
)
173169

174170
# Convert the global explanation data to a DataFrame
175171
global_explanation_df = pd.DataFrame(self.global_explanation)
@@ -185,9 +181,12 @@ def _generate_report(self):
185181
)
186182

187183
# Create a markdown section for the global explainability
188-
global_explanation_section = dp.Blocks(
189-
"### Global Explainability ",
190-
dp.DataTable(self.formatted_global_explanation),
184+
global_explanation_section = rc.Block(
185+
rc.Heading("Global Explanation of Models", level=2),
186+
rc.Text(
187+
"The following tables provide the feature attribution for the global explainability."
188+
),
189+
rc.DataTable(self.formatted_global_explanation),
191190
)
192191

193192
aggregate_local_explanations = pd.DataFrame()
@@ -199,30 +198,28 @@ def _generate_report(self):
199198
)
200199
self.formatted_local_explanation = aggregate_local_explanations
201200

202-
local_explanation_text = dp.Text(f"## Local Explanation of Models \n ")
203201
blocks = [
204-
dp.DataTable(
202+
rc.DataTable(
205203
local_ex_df.div(local_ex_df.abs().sum(axis=1), axis=0) * 100,
206204
label=s_id,
207205
)
208206
for s_id, local_ex_df in self.local_explanation.items()
209207
]
210208
local_explanation_section = (
211-
dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
209+
rc.Heading("Local Explanation of Models", level=2),
210+
rc.Select(blocks=blocks) if len(blocks) > 1 else blocks[0],
212211
)
213212

214213
# Append the global explanation text and section to the "all_sections" list
215214
all_sections = all_sections + [
216-
global_explanation_text,
217215
global_explanation_section,
218-
local_explanation_text,
219216
local_explanation_section,
220217
]
221218
except Exception as e:
222219
logger.warn(f"Failed to generate Explanations with error: {e}.")
223220
logger.debug(f"Full Traceback: {traceback.format_exc()}")
224221

225-
model_description = dp.Text(
222+
model_description = rc.Text(
226223
"An autoregressive integrated moving average, or ARIMA, is a statistical "
227224
"analysis model that uses time series data to either better understand the "
228225
"data set or to predict future trends. A statistical model is autoregressive if "

0 commit comments

Comments
 (0)