Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoralez committed Nov 14, 2023
1 parent 4fd5e0e commit 9c5dd76
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 437 deletions.
70 changes: 43 additions & 27 deletions nbs/src/adapters.prophet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,36 @@
" If your forecasting pipeline uses Prophet the `AutoARIMAProphet` adapter helps to\n",
" easily substitute Prophet with an AutoARIMA.\n",
"\n",
" **Parameters:**<br>\n",
" `growth`: String 'linear', 'logistic' or 'flat' to specify a linear, logistic or flat trend.<br>\n",
" `changepoints`: List of dates of potential changepoints. Otherwise selected automatically.<br>\n",
" `n_changepoints`: Number of potential changepoints to include.<br>\n",
" `changepoint_range`: Proportion of history in which trend changepoints will be estimated.<br>\n",
" `yearly_seasonality`: Fit yearly seasonality.\n",
" Can be 'auto', True, False, or a number of Fourier terms to generate.<br>\n",
" `weekly_seasonality`: Fit weekly seasonality.\n",
" Can be 'auto', True, False, or a number of Fourier terms to generate.<br>\n",
" `daily_seasonality`: Fit daily seasonality.\n",
" Can be 'auto', True, False, or a number of Fourier terms to generate.<br>\n",
" `holidays`: pandas.DataFrame with columns holiday (string) and ds (date type).<br>\n",
" `interval_width`: float, uncertainty forecast intervals width. `StatsForecast`'s level <br>\n",
" Parameters\n",
" ----------\n",
" growth : string\n",
" 'linear', 'logistic' or 'flat' to specify a linear, logistic or flat trend.\n",
" changepoints : List of dates\n",
" Potential changepoints. Otherwise selected automatically.\n",
" n_changepoints : int\n",
" Number of potential changepoints to include.\n",
" changepoint_range : float\n",
" Proportion of history in which trend changepoints will be estimated.\n",
" yearly_seasonality : str, bool or int\n",
" Fit yearly seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.\n",
" weekly_seasonality : str, bool or int\n",
" Fit weekly seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.\n",
" daily_seasonality : str, bool or int\n",
" Fit daily seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.\n",
" holidays : pandas.DataFrame\n",
" DataFrame with columns holiday (string) and ds (date type).\n",
" interval_width : float\n",
" Uncertainty forecast intervals width. `StatsForecast`'s level\n",
"\n",
" **Notes:**<br>\n",
" Notes\n",
" -----\n",
" You can create automated exogenous variables from the Prophet data processing pipeline\n",
" these exogenous will be included into `AutoARIMA`'s exogenous features. Parameters like \n",
" `seasonality_mode`, `seasonality_prior_scale`, `holidays_prior_scale`, `changepoint_prior_scale`,\n",
" `mcmc_samples`, `uncertainty_samples`, `stan_backend` are Prophet exclusive.\n",
"\n",
" **References:**<br>\n",
" References\n",
" ----------\n",
" [Sean J. Taylor, Benjamin Letham (2017). \"Prophet Forecasting at Scale\"](https://peerj.com/preprints/3190.pdf)\n",
" \n",
" [Oskar Triebe, Hansika Hewamalage, Polina Pilyugina, Nikolay Laptev, Christoph Bergmeir, Ram Rajagopal (2021). \"NeuralProphet: Explainable Forecasting at Scale\".](https://arxiv.org/pdf/2111.15397.pdf)\n",
Expand Down Expand Up @@ -241,16 +250,20 @@
" biasadj=biasadj,\n",
" period=period)\n",
" \n",
" def fit(self, df, disable_seasonal_features=True, **kwargs):\n",
" def fit(self, df, disable_seasonal_features=True):\n",
" \"\"\"Fit the AutoARIMAProphet adapter.\n",
"\n",
" **Parameters:**<br>\n",
" `df`: pandas.DataFrame, with columns ds (date type) and y, the time series.<br>\n",
" `disable_seasonal_features`: bool, Wheter disable Prophet's seasonal features.<br>\n",
" `kwargs`: Additional arguments.<br>\n",
" Parameters\n",
" ----------\n",
" df : pandas.DataFrame\n",
" DataFrame with columns ds (date type) and y, the time series.\n",
" disable_seasonal_features : bool (default=True)\n",
" Disable Prophet's seasonal features.\n",
" \n",
" **Returns:**<br>\n",
" `self`: `AutoARIMAProphet` adapter object with `AutoARIMA` fitted model.\n",
" Returns\n",
" -------\n",
" AutoARIMAProphet\n",
" Adapter object with `AutoARIMA` fitted model.\n",
" \"\"\"\n",
" if self.history is not None:\n",
" raise Exception('Prophet object can only be fit once. '\n",
Expand All @@ -272,7 +285,6 @@
" self.make_all_seasonality_features(history))\n",
" self.train_component_cols = component_cols\n",
" self.component_modes = modes\n",
" self.fit_kwargs = deepcopy(kwargs)\n",
" if disable_seasonal_features:\n",
" seas = tuple(self.seasonalities.keys())\n",
" seasonal_features = seasonal_features.loc[:,~seasonal_features.columns.str.startswith(seas)]\n",
Expand All @@ -287,11 +299,15 @@
" def predict(self, df=None):\n",
" \"\"\"Predict using the AutoARIMAProphet adapter.\n",
" \n",
" **Parameters:**<br>\n",
" `df`: pandas.DataFrame, with columns ds (date type) and y, the time series.<br>\n",
" Parameters\n",
" ----------\n",
" df : pandas.DataFrame\n",
" DataFrame with columns ds (date type) and y, the time series.\n",
" \n",
" **Returns:**<br>\n",
" `fcsts_df`: A pandas.DataFrame with the forecast components.\n",
" Returns\n",
" -------\n",
" pandas.DataFrame\n",
" DataFrame with the forecast components.\n",
" \"\"\"\n",
" if self.history is None:\n",
" raise Exception('Model has not been fit.')\n",
Expand Down
83 changes: 52 additions & 31 deletions nbs/src/core/distributed.fugue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@
" This class uses [Fugue](https://github.com/fugue-project/fugue) backend capable of distributing \n",
" computation on Spark, Dask and Ray without any rewrites.\n",
"\n",
" **Parameters:**<br>\n",
" `engine`: fugue.ExecutionEngine, a selection between Spark, Dask, and Ray.<br>\n",
" `conf`: fugue.Config, engine configuration.<br>\n",
" `**transform_kwargs`: additional kwargs for Fugue's transform method.<br>\n",
"\n",
" **Notes:**<br>\n",
" Parameters\n",
" ----------\n",
" engine : fugue.ExecutionEngine\n",
" A selection between Spark, Dask, and Ray.\n",
" conf : fugue.Config\n",
" Engine configuration.\n",
" **transform_kwargs\n",
" Additional kwargs for Fugue's transform method.\n",
"\n",
" Notes\n",
" -----\n",
" A short introduction to Fugue, with examples on how to scale pandas code to Spark, Dask or Ray\n",
" is available [here](https://fugue-tutorials.readthedocs.io/tutorials/quick_look/ten_minutes.html).\n",
" \"\"\"\n",
Expand Down Expand Up @@ -157,24 +162,33 @@
" This method uses Fugue's transform function, in combination with \n",
" `core.StatsForecast`'s forecast to efficiently fit a list of StatsForecast models.\n",
"\n",
" **Parameters:**<br>\n",
" `df`: pandas.DataFrame, with columns [`unique_id`, `ds`, `y`] and exogenous.<br>\n",
" `freq`: str, frequency of the data, [pandas available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).<br>\n",
" `models`: List[typing.Any], list of instantiated objects `StatsForecast.models`.<br>\n",
" `fallback_model`: Any, Model to be used if a model fails.<br>\n",
" `X_df`: pandas.DataFrame, with [unique_id, ds] columns and df’s future exogenous.\n",
" `**kwargs`: Additional `core.StatsForecast` parameters. Example forecast horizon `h`.<br>\n",
"\n",
" **Returns:**<br>\n",
" `fcsts_df`: pandas.DataFrame, with `models` columns for point predictions and probabilistic\n",
" predictions for all fitted `models`.<br>\n",
" Parameters\n",
" ----------\n",
" df : pandas.DataFrame\n",
" DataFrame with columns [`unique_id`, `ds`, `y`] and exogenous.\n",
" freq : str\n",
" Frequency of the data, [pandas available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).\n",
" models : List[typing.Any]\n",
" List of instantiated objects `StatsForecast.models`.\n",
" fallback_model : Any\n",
" Model to be used if a model fails.\n",
" X_df : pandas.DataFrame\n",
" DataFrame with [unique_id, ds] columns and df’s future exogenous.\n",
" **kwargs\n",
" Additional `core.StatsForecast` parameters. Example forecast horizon `h`.\n",
"\n",
" Returns\n",
" -------\n",
" fcsts_df : pandas.DataFrame\n",
" DataFrame with `models` columns for point predictions and probabilistic predictions for all fitted `models`\n",
" \n",
" **References:**<br>\n",
" References\n",
" ----------\n",
" For more information check the \n",
" [Fugue's transform](https://fugue-tutorials.readthedocs.io/tutorials/beginner/transform.html)\n",
" tutorial.<br>\n",
" tutorial.\n",
" The [core.StatsForecast's forecast](https://nixtla.github.io/statsforecast/core.html#statsforecast.forecast)\n",
" method documentation.<br>\n",
" method documentation.\n",
" Or the list of available [StatsForecast's models](https://nixtla.github.io/statsforecast/src/core/models.html).\n",
" \"\"\"\n",
" level = kwargs.get(\"level\", [])\n",
Expand Down Expand Up @@ -224,19 +238,26 @@
" provides better model's generalization measurements by increasing the test's length \n",
" and diversity.\n",
"\n",
" **Parameters:**<br>\n",
" `df`: pandas.DataFrame, with columns [`unique_id`, `ds`, `y`] and exogenous.<br>\n",
" `freq`: str, frequency of the data, [panda's available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).<br>\n",
" `models`: List[typing.Any], list of instantiated objects `StatsForecast.models`.<br>\n",
" `fallback_model`: Any, Model to be used if a model fails.<br>\n",
"\n",
" **Returns:**<br>\n",
" `fcsts_df`: pandas.DataFrame, with `models` columns for point predictions and probabilistic\n",
" predictions for all fitted `models`.<br>\n",
" Parameters\n",
" ----------\n",
" df : pandas.DataFrame\n",
" DataFrame with columns [`unique_id`, `ds`, `y`] and exogenous.\n",
" freq : str\n",
" Frequency of the data, [pandas available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).\n",
" models : List[typing.Any]\n",
" List of instantiated objects `StatsForecast.models`.\n",
" fallback_model : Any\n",
" Model to be used if a model fails.\n",
"\n",
" Returns\n",
" -------\n",
" pandas.DataFrame\n",
" DataFrame, with `models` columns for point predictions and probabilistic predictions for all fitted `models`.\n",
" \n",
" **References:**<br>\n",
" References\n",
" ----------\n",
" The [core.StatsForecast's cross validation](https://nixtla.github.io/statsforecast/core.html#statsforecast.cross_validation)\n",
" method documentation.<br>\n",
" method documentation.\n",
" [Rob J. Hyndman and George Athanasopoulos (2018). \"Forecasting principles and practice, Temporal Cross-Validation\"](https://otexts.com/fpp3/tscv.html).\n",
" \"\"\"\n",
" level = kwargs.get(\"level\", [])\n",
Expand Down
Loading

0 comments on commit 9c5dd76

Please sign in to comment.