From 15fdbce93eb00da7b2fc742d0158486eb28ec68f Mon Sep 17 00:00:00 2001 From: martinb-bb <105685594+martinb-bb@users.noreply.github.com> Date: Wed, 8 Feb 2023 14:07:07 -0500 Subject: [PATCH] brnn metrics --- openbb_terminal/forecast/brnn_model.py | 4 ++++ openbb_terminal/forecast/brnn_view.py | 7 +++++++ .../forecast/forecast_controller.py | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/openbb_terminal/forecast/brnn_model.py b/openbb_terminal/forecast/brnn_model.py index 4a1341f0a65..2cef8210b7c 100644 --- a/openbb_terminal/forecast/brnn_model.py +++ b/openbb_terminal/forecast/brnn_model.py @@ -38,6 +38,7 @@ def get_brnn_data( model_save_name: str = "brnn_model", force_reset: bool = True, save_checkpoints: bool = True, + metric: str = "mape", ) -> Tuple[ Optional[List[TimeSeries]], Optional[List[TimeSeries]], @@ -84,6 +85,8 @@ def get_brnn_data( discarded). Defaults to True. save_checkpoints: bool Whether or not to automatically save the untrained model and checkpoints from training. Defaults to True. + metric: str + Metric to use for model selection. Defaults to "mape". Returns ------- @@ -174,4 +177,5 @@ def get_brnn_data( train_split, forecast_horizon, n_predict, + metric, ) diff --git a/openbb_terminal/forecast/brnn_view.py b/openbb_terminal/forecast/brnn_view.py index 34b4225001d..1bfdde3f3c2 100644 --- a/openbb_terminal/forecast/brnn_view.py +++ b/openbb_terminal/forecast/brnn_view.py @@ -43,6 +43,7 @@ def display_brnn_forecast( end_date: Optional[datetime] = None, naive: bool = False, export_pred_raw: bool = False, + metric: str = "mape", external_axes: Optional[List[plt.axes]] = None, ): """Display BRNN forecast @@ -102,6 +103,10 @@ def display_brnn_forecast( naive: bool Whether to show the naive baseline. This just assumes the closing price will be the same as the previous day's closing price. Defaults to False. + export_pred_raw: bool + Whether to export the raw predicted values. Defaults to False. + metric: str + The metric to use for the model. Defaults to "mape". external_axes: Optional[List[plt.axes]] External axes to plot on """ @@ -137,6 +142,7 @@ def display_brnn_forecast( model_save_name=model_save_name, force_reset=force_reset, save_checkpoints=save_checkpoints, + metric=metric, ) if ticker_series == []: return @@ -160,6 +166,7 @@ def display_brnn_forecast( forecast_only=forecast_only, naive=naive, export_pred_raw=export_pred_raw, + metric=metric, external_axes=external_axes, ) if residuals: diff --git a/openbb_terminal/forecast/forecast_controller.py b/openbb_terminal/forecast/forecast_controller.py index 6d244bbb0bb..cf7b1b96c7b 100644 --- a/openbb_terminal/forecast/forecast_controller.py +++ b/openbb_terminal/forecast/forecast_controller.py @@ -2126,6 +2126,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2155,6 +2156,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2187,6 +2189,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2214,6 +2217,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2273,6 +2277,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2309,6 +2314,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2385,6 +2391,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2427,6 +2434,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2494,6 +2502,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2537,6 +2546,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2644,6 +2654,7 @@ class ForecastController(BaseController): naive=True, explainability_raw=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2677,6 +2688,7 @@ class ForecastController(BaseController): naive=ns_parser.naive, explainability_raw=ns_parser.explainability_raw, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2728,6 +2740,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2769,6 +2782,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2856,6 +2870,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -2899,6 +2914,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -2972,6 +2988,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -3015,6 +3032,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger) @@ -3106,6 +3124,7 @@ class ForecastController(BaseController): end=True, naive=True, export_pred_raw=True, + metric=True, ) ns_parser = self.parse_known_args_and_warn( parser, @@ -3150,6 +3169,7 @@ class ForecastController(BaseController): end_date=ns_parser.s_end_date, naive=ns_parser.naive, export_pred_raw=ns_parser.export_pred_raw, + metric=ns_parser.metric, ) @log_start_end(log=logger)