44# 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
7- import json
7+ import fsspec
8+ import numpy as np
89import os
10+ import pandas as pd
911import tempfile
1012import time
13+ import traceback
1114from abc import ABC , abstractmethod
1215from typing import Tuple
13- import traceback
14-
15- import fsspec
16- import numpy as np
17- import pandas as pd
1816
19- from ads .opctl .operator .lowcode .forecast .utils import (
20- default_signer ,
21- evaluate_train_metrics ,
22- get_forecast_plots ,
23- _build_metrics_df ,
24- _build_metrics_per_horizon ,
25- load_pkl ,
26- write_pkl ,
27- _label_encode_dataframe ,
28- )
17+ from ads .common .decorator .runtime_dependency import runtime_dependency
2918from ads .common .object_storage_details import ObjectStorageDetails
3019from ads .opctl import logger
31-
3220from ads .opctl .operator .lowcode .common .utils import (
3321 human_time_friendly ,
3422 enable_print ,
3725 merged_category_column_name ,
3826 datetime_to_seconds ,
3927 seconds_to_datetime ,
40- find_output_dirname ,
4128)
29+ from ads .opctl .operator .lowcode .forecast .model .forecast_datasets import TestData
30+ from ads .opctl .operator .lowcode .forecast .utils import (
31+ default_signer ,
32+ evaluate_train_metrics ,
33+ get_forecast_plots ,
34+ get_auto_select_plot ,
35+ _build_metrics_df ,
36+ _build_metrics_per_horizon ,
37+ load_pkl ,
38+ write_pkl ,
39+ _label_encode_dataframe ,
40+ )
41+ from .forecast_datasets import ForecastDatasets
4242from ..const import (
4343 SUMMARY_METRICS_HORIZON_LIMIT ,
4444 SupportedMetrics ,
4545 SupportedModels ,
4646 SpeedAccuracyMode ,
47+ AUTO_SELECT
4748)
4849from ..operator_config import ForecastOperatorConfig , ForecastOperatorSpec
49- from ads .common .decorator .runtime_dependency import runtime_dependency
50- from .forecast_datasets import ForecastDatasets , ForecastOutput
51- from ads .opctl .operator .lowcode .forecast .model .forecast_datasets import TestData
5250
5351
5452class ForecastOperatorBaseModel (ABC ):
@@ -250,6 +248,23 @@ def generate_report(self):
250248 sec9 = rc .DataTable (self .eval_metrics , index = True )
251249 train_metrics_sections = [sec9_text , sec9 ]
252250
251+ backtest_sections = []
252+ if self .spec .model == AUTO_SELECT :
253+ output_dir = self .spec .output_directory .url
254+ backtest_report_name = "backtest_stats.csv"
255+ backtest_stats = pd .read_csv (f"{ output_dir } /{ backtest_report_name } " )
256+ average_dict = backtest_stats .mean ().to_dict ()
257+ del average_dict ['backtest' ]
258+ best_model = min (average_dict , key = average_dict .get )
259+ backtest_text = rc .Heading ("Back Testing Metrics" , level = 2 )
260+ summary_text = rc .Text (
261+ f"Overall, the average scores for the models are { average_dict } , with { best_model } "
262+ f" being identified as the top-performing model during backtesting." )
263+ backtest_table = rc .DataTable (backtest_stats , index = True )
264+ liner_plot = get_auto_select_plot (backtest_stats )
265+ backtest_sections = [backtest_text , backtest_table , summary_text , liner_plot ]
266+
267+
253268 forecast_plots = []
254269 if len (self .forecast_output .list_series_ids ()) > 0 :
255270 forecast_text = rc .Heading (
@@ -276,6 +291,7 @@ def generate_report(self):
276291 yaml_appendix = rc .Yaml (self .config .to_dict ())
277292 report_sections = (
278293 [summary ]
294+ + backtest_sections
279295 + forecast_plots
280296 + other_sections
281297 + test_metrics_sections
@@ -409,7 +425,7 @@ def _save_report(
409425 """Saves resulting reports to the given folder."""
410426 import report_creator as rc
411427
412- unique_output_dir = find_output_dirname ( self .spec .output_directory )
428+ unique_output_dir = self .spec .output_directory . url
413429
414430 if ObjectStorageDetails .is_oci_path (unique_output_dir ):
415431 storage_options = default_signer ()
0 commit comments