oracle-ads 2.11.7__py3-none-any.whl → 2.11.9__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.
Files changed (47) hide show
  1. ads/aqua/__init__.py +24 -14
  2. ads/aqua/base.py +0 -2
  3. ads/aqua/cli.py +50 -2
  4. ads/aqua/decorator.py +8 -0
  5. ads/aqua/deployment.py +37 -34
  6. ads/aqua/evaluation.py +106 -49
  7. ads/aqua/extension/base_handler.py +18 -10
  8. ads/aqua/extension/common_handler.py +21 -2
  9. ads/aqua/extension/deployment_handler.py +1 -4
  10. ads/aqua/extension/evaluation_handler.py +1 -2
  11. ads/aqua/extension/finetune_handler.py +0 -1
  12. ads/aqua/extension/ui_handler.py +1 -12
  13. ads/aqua/extension/utils.py +4 -4
  14. ads/aqua/finetune.py +24 -11
  15. ads/aqua/model.py +2 -4
  16. ads/aqua/utils.py +40 -23
  17. ads/cli.py +19 -1
  18. ads/common/serializer.py +5 -4
  19. ads/common/utils.py +6 -2
  20. ads/config.py +1 -0
  21. ads/llm/serializers/runnable_parallel.py +7 -1
  22. ads/model/datascience_model.py +20 -0
  23. ads/opctl/operator/lowcode/anomaly/README.md +1 -1
  24. ads/opctl/operator/lowcode/anomaly/environment.yaml +1 -1
  25. ads/opctl/operator/lowcode/anomaly/model/automlx.py +15 -10
  26. ads/opctl/operator/lowcode/anomaly/model/autots.py +9 -10
  27. ads/opctl/operator/lowcode/anomaly/model/base_model.py +34 -37
  28. ads/opctl/operator/lowcode/anomaly/model/tods.py +4 -4
  29. ads/opctl/operator/lowcode/anomaly/schema.yaml +1 -1
  30. ads/opctl/operator/lowcode/forecast/README.md +1 -1
  31. ads/opctl/operator/lowcode/forecast/environment.yaml +4 -4
  32. ads/opctl/operator/lowcode/forecast/model/arima.py +19 -21
  33. ads/opctl/operator/lowcode/forecast/model/automlx.py +36 -42
  34. ads/opctl/operator/lowcode/forecast/model/autots.py +41 -25
  35. ads/opctl/operator/lowcode/forecast/model/base_model.py +93 -107
  36. ads/opctl/operator/lowcode/forecast/model/neuralprophet.py +51 -45
  37. ads/opctl/operator/lowcode/forecast/model/prophet.py +32 -27
  38. ads/opctl/operator/lowcode/forecast/schema.yaml +2 -2
  39. ads/opctl/operator/lowcode/forecast/utils.py +4 -4
  40. ads/opctl/operator/lowcode/pii/README.md +1 -1
  41. ads/opctl/operator/lowcode/pii/environment.yaml +1 -1
  42. ads/opctl/operator/lowcode/pii/model/report.py +71 -70
  43. {oracle_ads-2.11.7.dist-info → oracle_ads-2.11.9.dist-info}/METADATA +5 -5
  44. {oracle_ads-2.11.7.dist-info → oracle_ads-2.11.9.dist-info}/RECORD +47 -47
  45. {oracle_ads-2.11.7.dist-info → oracle_ads-2.11.9.dist-info}/LICENSE.txt +0 -0
  46. {oracle_ads-2.11.7.dist-info → oracle_ads-2.11.9.dist-info}/WHEEL +0 -0
  47. {oracle_ads-2.11.7.dist-info → oracle_ads-2.11.9.dist-info}/entry_points.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*--
3
3
 
4
- # Copyright (c) 2023 Oracle and/or its affiliates.
4
+ # Copyright (c) 2023, 2024 Oracle and/or its affiliates.
5
5
  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
 
7
7
  import numpy as np
@@ -41,20 +41,20 @@ from .forecast_datasets import ForecastDatasets, ForecastOutput
41
41
  import traceback
42
42
 
43
43
 
44
- def _get_np_metrics_dict(selected_metric):
45
- metric_translation = {
46
- "mape": MeanAbsolutePercentageError,
47
- "smape": SymmetricMeanAbsolutePercentageError,
48
- "mae": MeanAbsoluteError,
49
- "r2": R2Score,
50
- "rmse": MeanSquaredError,
51
- }
52
- if selected_metric not in metric_translation.keys():
53
- logger.warn(
54
- f"Could not find the metric: {selected_metric} in torchmetrics. Defaulting to MAE and RMSE"
55
- )
56
- return {"MAE": MeanAbsoluteError(), "RMSE": MeanSquaredError()}
57
- return {selected_metric: metric_translation[selected_metric]()}
44
+ # def _get_np_metrics_dict(selected_metric):
45
+ # metric_translation = {
46
+ # "mape": MeanAbsolutePercentageError,
47
+ # "smape": SymmetricMeanAbsolutePercentageError,
48
+ # "mae": MeanAbsoluteError,
49
+ # "r2": R2Score,
50
+ # "rmse": MeanSquaredError,
51
+ # }
52
+ # if selected_metric not in metric_translation.keys():
53
+ # logger.warn(
54
+ # f"Could not find the metric: {selected_metric} in torchmetrics. Defaulting to MAE and RMSE"
55
+ # )
56
+ # return {"MAE": MeanAbsoluteError(), "RMSE": MeanSquaredError()}
57
+ # return {selected_metric: metric_translation[selected_metric]()}
58
58
 
59
59
 
60
60
  @runtime_dependency(
@@ -70,7 +70,7 @@ def _fit_model(data, params, additional_regressors, select_metric):
70
70
  disable_print()
71
71
 
72
72
  m = NeuralProphet(**params)
73
- m.metrics = _get_np_metrics_dict(select_metric)
73
+ # m.metrics = _get_np_metrics_dict(select_metric)
74
74
  for add_reg in additional_regressors:
75
75
  m = m.add_future_regressor(name=add_reg)
76
76
  m.fit(df=data)
@@ -135,7 +135,8 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
135
135
  data=data_i,
136
136
  params=model_kwargs,
137
137
  additional_regressors=self.additional_regressors,
138
- select_metric=self.spec.metric,
138
+ select_metric=None,
139
+ # select_metric=self.spec.metric,
139
140
  )
140
141
 
141
142
  logger.debug(
@@ -209,6 +210,7 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
209
210
  logger.debug("===========Done===========")
210
211
  except Exception as e:
211
212
  self.errors_dict[s_id] = {"model_name": self.spec.model, "error": str(e)}
213
+ raise e
212
214
 
213
215
  def _build_model(self) -> pd.DataFrame:
214
216
  full_data_dict = self.datasets.get_data_by_series()
@@ -309,44 +311,52 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
309
311
  return selected_params
310
312
 
311
313
  def _generate_report(self):
312
- import datapane as dp
314
+ import report_creator as rc
315
+
313
316
  series_ids = self.models.keys()
314
317
  all_sections = []
315
318
  if len(series_ids) > 0:
316
319
  try:
317
- sec1_text = dp.Text(
318
- "## Forecast Overview \nThese plots show your "
319
- "forecast in the context of historical data."
320
- )
321
320
  sec1 = _select_plot_list(
322
321
  lambda s_id: self.models[s_id].plot(self.outputs[s_id]),
323
322
  series_ids=series_ids,
324
323
  )
325
- all_sections = all_sections + [sec1_text, sec1]
324
+ section_1 = rc.Block(
325
+ rc.Heading("Forecast Overview", level=2),
326
+ rc.Text(
327
+ "These plots show your forecast in the context of historical data."
328
+ ),
329
+ sec1,
330
+ )
331
+ all_sections = all_sections + [section_1]
326
332
  except Exception as e:
327
333
  logger.debug(f"Failed to plot with exception: {e.args}")
328
334
 
329
335
  try:
330
- sec2_text = dp.Text(f"## Forecast Broken Down by Trend Component")
331
336
  sec2 = _select_plot_list(
332
337
  lambda s_id: self.models[s_id].plot_components(self.outputs[s_id]),
333
338
  series_ids=series_ids,
334
339
  )
335
- all_sections = all_sections + [sec2_text, sec2]
340
+ section_2 = rc.Block(
341
+ rc.Heading("Forecast Broken Down by Trend Component", level=2), sec2
342
+ )
343
+ all_sections = all_sections + [section_2]
336
344
  except Exception as e:
337
345
  logger.debug(f"Failed to plot with exception: {e.args}")
338
346
 
339
347
  try:
340
- sec3_text = dp.Text(f"## Forecast Parameter Plots")
341
348
  sec3 = _select_plot_list(
342
349
  lambda s_id: self.models[s_id].plot_parameters(),
343
350
  series_ids=series_ids,
344
351
  )
345
- all_sections = all_sections + [sec3_text, sec3]
352
+ section_3 = rc.Block(
353
+ rc.Heading("Forecast Parameter Plots", level=2), sec3
354
+ )
355
+ all_sections = all_sections + [section_3]
346
356
  except Exception as e:
347
357
  logger.debug(f"Failed to plot with exception: {e.args}")
348
358
 
349
- sec5_text = dp.Text(f"## Neural Prophet Model Parameters")
359
+ sec5_text = rc.Heading("Neural Prophet Model Parameters", level=2)
350
360
  model_states = []
351
361
  for i, (s_id, m) in enumerate(self.models.items()):
352
362
  model_states.append(
@@ -357,7 +367,7 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
357
367
  )
358
368
  )
359
369
  all_model_states = pd.concat(model_states, axis=1)
360
- sec5 = dp.DataTable(all_model_states)
370
+ sec5 = rc.DataTable(all_model_states, index=True)
361
371
 
362
372
  all_sections = all_sections + [sec5_text, sec5]
363
373
 
@@ -366,35 +376,31 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
366
376
  # If the key is present, call the "explain_model" method
367
377
  self.explain_model()
368
378
 
369
- # Create a markdown text block for the global explanation section
370
- global_explanation_text = dp.Text(
371
- f"## Global Explanation of Models \n "
372
- "The following tables provide the feature attribution for the global explainability."
373
- )
374
-
375
379
  # Create a markdown section for the global explainability
376
- global_explanation_section = dp.Blocks(
377
- "### Global Explainability ",
378
- dp.DataTable(self.formatted_global_explanation),
380
+ global_explanation_section = rc.Block(
381
+ rc.Heading("Global Explainability", level=2),
382
+ rc.Text(
383
+ "The following tables provide the feature attribution for the global explainability."
384
+ ),
385
+ rc.DataTable(self.formatted_global_explanation, index=True),
379
386
  )
380
387
 
381
- local_explanation_text = dp.Text(f"## Local Explanation of Models \n ")
382
388
  blocks = [
383
- dp.DataTable(
389
+ rc.DataTable(
384
390
  local_ex_df.drop("Series", axis=1),
385
391
  label=s_id,
392
+ index=True,
386
393
  )
387
394
  for s_id, local_ex_df in self.local_explanation.items()
388
395
  ]
389
- local_explanation_section = (
390
- dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
396
+ local_explanation_section = rc.Block(
397
+ rc.Heading("Local Explanation of Models", level=2),
398
+ rc.Select(blocks=blocks),
391
399
  )
392
400
 
393
401
  # Append the global explanation text and section to the "all_sections" list
394
402
  all_sections = all_sections + [
395
- global_explanation_text,
396
403
  global_explanation_section,
397
- local_explanation_text,
398
404
  local_explanation_section,
399
405
  ]
400
406
  except Exception as e:
@@ -402,7 +408,7 @@ class NeuralProphetOperatorModel(ForecastOperatorBaseModel):
402
408
  logger.warn(f"Failed to generate Explanations with error: {e}.")
403
409
  logger.debug(f"Full Traceback: {traceback.format_exc()}")
404
410
 
405
- model_description = dp.Text(
411
+ model_description = rc.Text(
406
412
  "NeuralProphet is an easy to learn framework for interpretable time "
407
413
  "series forecasting. NeuralProphet is built on PyTorch and combines "
408
414
  "Neural Network and traditional time-series algorithms, inspired by "
@@ -133,7 +133,6 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
133
133
  }
134
134
 
135
135
  def _build_model(self) -> pd.DataFrame:
136
-
137
136
  full_data_dict = self.datasets.get_data_by_series()
138
137
  self.models = dict()
139
138
  self.outputs = dict()
@@ -160,6 +159,7 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
160
159
  def run_tuning(self, data_i, model_kwargs_i):
161
160
  from prophet import Prophet
162
161
  from prophet.diagnostics import cross_validation, performance_metrics
162
+
163
163
  def objective(trial):
164
164
  params = {
165
165
  "seasonality_mode": trial.suggest_categorical(
@@ -243,29 +243,34 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
243
243
  return model_kwargs_i
244
244
 
245
245
  def _generate_report(self):
246
- import datapane as dp
246
+ import report_creator as rc
247
247
  from prophet.plot import add_changepoints_to_plot
248
+
248
249
  series_ids = self.models.keys()
249
250
  all_sections = []
250
251
  if len(series_ids) > 0:
251
- sec1_text = dp.Text(
252
- "## Forecast Overview \n"
253
- "These plots show your forecast in the context of historical data."
254
- )
255
252
  sec1 = _select_plot_list(
256
253
  lambda s_id: self.models[s_id].plot(
257
254
  self.outputs[s_id], include_legend=True
258
255
  ),
259
256
  series_ids=series_ids,
260
257
  )
258
+ section_1 = rc.Block(
259
+ rc.Heading("Forecast Overview", level=2),
260
+ rc.Text(
261
+ "These plots show your forecast in the context of historical data."
262
+ ),
263
+ sec1,
264
+ )
261
265
 
262
- sec2_text = dp.Text(f"## Forecast Broken Down by Trend Component")
263
266
  sec2 = _select_plot_list(
264
267
  lambda s_id: self.models[s_id].plot_components(self.outputs[s_id]),
265
268
  series_ids=series_ids,
266
269
  )
270
+ section_2 = rc.Block(
271
+ rc.Heading("Forecast Broken Down by Trend Component", level=2), sec2
272
+ )
267
273
 
268
- sec3_text = dp.Text(f"## Forecast Changepoints")
269
274
  sec3_figs = {
270
275
  s_id: self.models[s_id].plot(self.outputs[s_id]) for s_id in series_ids
271
276
  }
@@ -273,11 +278,14 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
273
278
  add_changepoints_to_plot(
274
279
  sec3_figs[s_id].gca(), self.models[s_id], self.outputs[s_id]
275
280
  )
276
- sec3 = _select_plot_list(lambda s_id: sec3_figs[s_id], series_ids=series_ids)
281
+ sec3 = _select_plot_list(
282
+ lambda s_id: sec3_figs[s_id], series_ids=series_ids
283
+ )
284
+ section_3 = rc.Block(rc.Heading("Forecast Changepoints", level=2), sec3)
277
285
 
278
- all_sections = [sec1_text, sec1, sec2_text, sec2, sec3_text, sec3]
286
+ all_sections = [section_1, section_2, section_3]
279
287
 
280
- sec5_text = dp.Text(f"## Prophet Model Seasonality Components")
288
+ sec5_text = rc.Heading("Prophet Model Seasonality Components", level=2)
281
289
  model_states = []
282
290
  for s_id in series_ids:
283
291
  m = self.models[s_id]
@@ -291,7 +299,7 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
291
299
  )
292
300
  all_model_states = pd.concat(model_states, axis=1)
293
301
  if not all_model_states.empty:
294
- sec5 = dp.DataTable(all_model_states)
302
+ sec5 = rc.DataTable(all_model_states, index=True)
295
303
  all_sections = all_sections + [sec5_text, sec5]
296
304
 
297
305
  if self.spec.generate_explanations:
@@ -299,12 +307,6 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
299
307
  # If the key is present, call the "explain_model" method
300
308
  self.explain_model()
301
309
 
302
- # Create a markdown text block for the global explanation section
303
- global_explanation_text = dp.Text(
304
- f"## Global Explanation of Models \n "
305
- "The following tables provide the feature attribution for the global explainability."
306
- )
307
-
308
310
  # Convert the global explanation data to a DataFrame
309
311
  global_explanation_df = pd.DataFrame(self.global_explanation)
310
312
 
@@ -313,9 +315,12 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
313
315
  )
314
316
 
315
317
  # Create a markdown section for the global explainability
316
- global_explanation_section = dp.Blocks(
317
- "### Global Explainability ",
318
- dp.DataTable(self.formatted_global_explanation),
318
+ global_explanation_section = rc.Block(
319
+ rc.Heading("Global Explanation of Models", level=2),
320
+ rc.Text(
321
+ "The following tables provide the feature attribution for the global explainability."
322
+ ),
323
+ rc.DataTable(self.formatted_global_explanation, index=True),
319
324
  )
320
325
 
321
326
  aggregate_local_explanations = pd.DataFrame()
@@ -327,21 +332,21 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
327
332
  )
328
333
  self.formatted_local_explanation = aggregate_local_explanations
329
334
 
330
- local_explanation_text = dp.Text(f"## Local Explanation of Models \n ")
331
335
  blocks = [
332
- dp.DataTable(
336
+ rc.DataTable(
333
337
  local_ex_df.div(local_ex_df.abs().sum(axis=1), axis=0) * 100,
334
338
  label=s_id,
339
+ index=True,
335
340
  )
336
341
  for s_id, local_ex_df in self.local_explanation.items()
337
342
  ]
338
- local_explanation_section = (
339
- dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
343
+ local_explanation_section = rc.Block(
344
+ rc.Heading("Local Explanation of Models", level=2),
345
+ rc.Select(blocks=blocks),
340
346
  )
341
347
 
342
348
  # Append the global explanation text and section to the "all_sections" list
343
349
  all_sections = all_sections + [
344
- global_explanation_text,
345
350
  global_explanation_section,
346
351
  local_explanation_text,
347
352
  local_explanation_section,
@@ -351,7 +356,7 @@ class ProphetOperatorModel(ForecastOperatorBaseModel):
351
356
  logger.warn(f"Failed to generate Explanations with error: {e}.")
352
357
  logger.debug(f"Full Traceback: {traceback.format_exc()}")
353
358
 
354
- model_description = dp.Text(
359
+ model_description = (
355
360
  "Prophet is a procedure for forecasting time series data based on an additive "
356
361
  "model where non-linear trends are fit with yearly, weekly, and daily seasonality, "
357
362
  "plus holiday effects. It works best with time series that have strong seasonal "
@@ -302,11 +302,11 @@ spec:
302
302
  missing_value_imputation:
303
303
  type: boolean
304
304
  required: false
305
- default: true
305
+ default: false
306
306
  outlier_treatment:
307
307
  type: boolean
308
308
  required: false
309
- default: true
309
+ default: false
310
310
 
311
311
  generate_explanations:
312
312
  type: boolean
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*--
3
3
 
4
- # Copyright (c) 2023 Oracle and/or its affiliates.
4
+ # Copyright (c) 2023, 2024 Oracle and/or its affiliates.
5
5
  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
 
7
7
  import os
@@ -258,10 +258,10 @@ def evaluate_train_metrics(output, metrics_col_name=None):
258
258
 
259
259
 
260
260
  def _select_plot_list(fn, series_ids):
261
- import datapane as dp
261
+ import report_creator as rc
262
262
 
263
- blocks = [dp.Plot(fn(s_id=s_id), label=s_id) for s_id in series_ids]
264
- return dp.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
263
+ blocks = [rc.Widget(fn(s_id=s_id), label=s_id) for s_id in series_ids]
264
+ return rc.Select(blocks=blocks) if len(blocks) > 1 else blocks[0]
265
265
 
266
266
 
267
267
  def _add_unit(num, unit):
@@ -33,7 +33,7 @@ To run pii operator locally, create and activate a new conda environment (`ads-p
33
33
 
34
34
  ```yaml
35
35
  - aiohttp
36
- - datapane
36
+ - report-creator
37
37
  - gender_guesser
38
38
  - nameparser
39
39
  - oracle_ads[opctl]
@@ -6,7 +6,7 @@ dependencies:
6
6
  - pip
7
7
  - pip:
8
8
  - aiohttp
9
- - datapane
9
+ - report-creator
10
10
  - gender_guesser
11
11
  - nameparser
12
12
  - oracle_ads[opctl]