From f4b7c6e6a603a9d172c050e348f11bf8dec1b650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Morales?= Date: Tue, 2 Jul 2024 18:25:00 -0600 Subject: [PATCH] support prediction intervals in auto --- mlforecast/auto.py | 14 ++- nbs/auto.ipynb | 235 ++++++++++++++++++++++++++++++--------------- 2 files changed, 170 insertions(+), 79 deletions(-) diff --git a/mlforecast/auto.py b/mlforecast/auto.py index e2d3d628..96e30b61 100644 --- a/mlforecast/auto.py +++ b/mlforecast/auto.py @@ -27,6 +27,7 @@ LocalStandardScaler, GlobalSklearnTransformer, ) +from .utils import PredictionIntervals # %% ../nbs/auto.ipynb 4 def lightgbm_space(trial: optuna.Trial): @@ -442,6 +443,7 @@ def fit( study_kwargs: Optional[Dict[str, Any]] = None, optimize_kwargs: Optional[Dict[str, Any]] = None, fitted: bool = False, + prediction_intervals: Optional[PredictionIntervals] = None, ) -> "AutoMLForecast": """Carry out the optimization process. Each model is optimized independently and the best one is trained on all data @@ -475,6 +477,8 @@ def fit( Keyword arguments to be passed to the optuna.Study.optimize method. fitted : bool (default=False) Whether to compute the fitted values when retraining the best model. + prediction_intervals : + Configuration to calibrate prediction intervals when retraining the best model. Returns ------- @@ -538,6 +542,7 @@ def config_fn(trial: optuna.Trial) -> Dict[str, Any]: self.results_[name] = study best_config = study.best_trial.user_attrs["config"] best_config["mlf_fit_params"].pop("fitted", None) + best_config["mlf_fit_params"].pop("prediction_intervals", None) best_model = clone(auto_model.model) best_model.set_params(**best_config["model_params"]) self.models_[name] = MLForecast( @@ -548,6 +553,7 @@ def config_fn(trial: optuna.Trial) -> Dict[str, Any]: self.models_[name].fit( df, fitted=fitted, + prediction_intervals=prediction_intervals, **best_config["mlf_fit_params"], ) return self @@ -556,6 +562,7 @@ def predict( self, h: int, X_df: Optional[DataFrame] = None, + level: Optional[List[Union[int, float]]] = None, ) -> DataFrame: """ "Compute forecasts @@ -565,6 +572,8 @@ def predict( Number of periods to predict. X_df : pandas or polars DataFrame, optional (default=None) Dataframe with the future exogenous features. Should have the id column and the time column. + level : list of ints or floats, optional (default=None) + Confidence levels between 0 and 100 for prediction intervals. Returns ------- @@ -573,11 +582,12 @@ def predict( """ all_preds = None for name, model in self.models_.items(): - preds = model.predict(h=h, X_df=X_df) + preds = model.predict(h=h, X_df=X_df, level=level) if all_preds is None: all_preds = preds else: - all_preds = ufp.assign_columns(all_preds, name, preds[name]) + model_cols = [c for c in preds.columns if c not in all_preds.columns] + all_preds = ufp.horizontal_concat([all_preds, preds[model_cols]]) return all_preds def save(self, path: Union[str, Path]) -> None: diff --git a/nbs/auto.ipynb b/nbs/auto.ipynb index a06e01ca..dcda602e 100644 --- a/nbs/auto.ipynb +++ b/nbs/auto.ipynb @@ -55,7 +55,8 @@ "from mlforecast.core import Freq, _get_model_name, _name_models\n", "from mlforecast.lag_transforms import ExponentiallyWeightedMean, RollingMean\n", "from mlforecast.optimization import _TrialToConfig, mlforecast_objective\n", - "from mlforecast.target_transforms import Differences, LocalStandardScaler, GlobalSklearnTransformer" + "from mlforecast.target_transforms import Differences, LocalStandardScaler, GlobalSklearnTransformer\n", + "from mlforecast.utils import PredictionIntervals" ] }, { @@ -277,7 +278,7 @@ "> AutoModel (model:sklearn.base.BaseEstimator,\n", "> config:Callable[[optuna.trial._trial.Trial],Dict[str,Any]])\n", "\n", - "Structure to hold a model and its search space\n", + "*Structure to hold a model and its search space*\n", "\n", "| | **Type** | **Details** |\n", "| -- | -------- | ----------- |\n", @@ -294,7 +295,7 @@ "> AutoModel (model:sklearn.base.BaseEstimator,\n", "> config:Callable[[optuna.trial._trial.Trial],Dict[str,Any]])\n", "\n", - "Structure to hold a model and its search space\n", + "*Structure to hold a model and its search space*\n", "\n", "| | **Type** | **Details** |\n", "| -- | -------- | ----------- |\n", @@ -518,6 +519,7 @@ " study_kwargs: Optional[Dict[str, Any]] = None,\n", " optimize_kwargs: Optional[Dict[str, Any]] = None,\n", " fitted: bool = False,\n", + " prediction_intervals: Optional[PredictionIntervals] = None,\n", " ) -> 'AutoMLForecast':\n", " \"\"\"Carry out the optimization process.\n", " Each model is optimized independently and the best one is trained on all data\n", @@ -551,6 +553,8 @@ " Keyword arguments to be passed to the optuna.Study.optimize method.\n", " fitted : bool (default=False)\n", " Whether to compute the fitted values when retraining the best model.\n", + " prediction_intervals : \n", + " Configuration to calibrate prediction intervals when retraining the best model.\n", "\n", " Returns\n", " -------\n", @@ -611,6 +615,7 @@ " self.results_[name] = study\n", " best_config = study.best_trial.user_attrs['config']\n", " best_config['mlf_fit_params'].pop('fitted', None)\n", + " best_config['mlf_fit_params'].pop('prediction_intervals', None)\n", " best_model = clone(auto_model.model)\n", " best_model.set_params(**best_config['model_params'])\n", " self.models_[name] = MLForecast(\n", @@ -621,6 +626,7 @@ " self.models_[name].fit(\n", " df,\n", " fitted=fitted,\n", + " prediction_intervals=prediction_intervals,\n", " **best_config['mlf_fit_params'],\n", " )\n", " return self\n", @@ -629,6 +635,7 @@ " self,\n", " h: int,\n", " X_df: Optional[DataFrame] = None,\n", + " level: Optional[List[Union[int, float]]] = None,\n", " ) -> DataFrame:\n", " \"\"\"\"Compute forecasts\n", "\n", @@ -638,6 +645,8 @@ " Number of periods to predict.\n", " X_df : pandas or polars DataFrame, optional (default=None)\n", " Dataframe with the future exogenous features. Should have the id column and the time column.\n", + " level : list of ints or floats, optional (default=None)\n", + " Confidence levels between 0 and 100 for prediction intervals.\n", "\n", " Returns\n", " -------\n", @@ -646,11 +655,12 @@ " \"\"\"\n", " all_preds = None\n", " for name, model in self.models_.items():\n", - " preds = model.predict(h=h, X_df=X_df)\n", + " preds = model.predict(h=h, X_df=X_df, level=level)\n", " if all_preds is None:\n", " all_preds = preds\n", " else:\n", - " all_preds = ufp.assign_columns(all_preds, name, preds[name])\n", + " model_cols = [c for c in preds.columns if c not in all_preds.columns]\n", + " all_preds = ufp.horizontal_concat([all_preds, preds[model_cols]])\n", " return all_preds\n", "\n", " def save(self, path: Union[str, Path]) -> None:\n", @@ -717,7 +727,7 @@ "> rial._trial.Trial],Dict[str,Any]]]=None,\n", "> num_threads:int=1)\n", "\n", - "Hyperparameter optimization helper\n", + "*Hyperparameter optimization helper*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -743,7 +753,7 @@ "> rial._trial.Trial],Dict[str,Any]]]=None,\n", "> num_threads:int=1)\n", "\n", - "Hyperparameter optimization helper\n", + "*Hyperparameter optimization helper*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -790,10 +800,11 @@ "> target_col:str='y',\n", "> study_kwargs:Optional[Dict[str,Any]]=None,\n", "> optimize_kwargs:Optional[Dict[str,Any]]=None,\n", - "> fitted:bool=False)\n", + "> fitted:bool=False, prediction_intervals:Optional[mlfo\n", + "> recast.utils.PredictionIntervals]=None)\n", "\n", - "Carry out the optimization process.\n", - "Each model is optimized independently and the best one is trained on all data\n", + "*Carry out the optimization process.\n", + "Each model is optimized independently and the best one is trained on all data*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -809,6 +820,7 @@ "| study_kwargs | Optional | None | Keyword arguments to be passed to the optuna.Study constructor. |\n", "| optimize_kwargs | Optional | None | Keyword arguments to be passed to the optuna.Study.optimize method. |\n", "| fitted | bool | False | Whether to compute the fitted values when retraining the best model. |\n", + "| prediction_intervals | Optional | None | Configuration to calibrate prediction intervals when retraining the best model. |\n", "| **Returns** | **AutoMLForecast** | | **object with best models and optimization results** |" ], "text/plain": [ @@ -829,10 +841,11 @@ "> target_col:str='y',\n", "> study_kwargs:Optional[Dict[str,Any]]=None,\n", "> optimize_kwargs:Optional[Dict[str,Any]]=None,\n", - "> fitted:bool=False)\n", + "> fitted:bool=False, prediction_intervals:Optional[mlfo\n", + "> recast.utils.PredictionIntervals]=None)\n", "\n", - "Carry out the optimization process.\n", - "Each model is optimized independently and the best one is trained on all data\n", + "*Carry out the optimization process.\n", + "Each model is optimized independently and the best one is trained on all data*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -848,6 +861,7 @@ "| study_kwargs | Optional | None | Keyword arguments to be passed to the optuna.Study constructor. |\n", "| optimize_kwargs | Optional | None | Keyword arguments to be passed to the optuna.Study.optimize method. |\n", "| fitted | bool | False | Whether to compute the fitted values when retraining the best model. |\n", + "| prediction_intervals | Optional | None | Configuration to calibrate prediction intervals when retraining the best model. |\n", "| **Returns** | **AutoMLForecast** | | **object with best models and optimization results** |" ] }, @@ -876,14 +890,16 @@ "### AutoMLForecast.predict\n", "\n", "> AutoMLForecast.predict (h:int, X_df:Union[pandas.core.frame.DataFrame,pol\n", - "> ars.dataframe.frame.DataFrame,NoneType]=None)\n", + "> ars.dataframe.frame.DataFrame,NoneType]=None,\n", + "> level:Optional[List[Union[int,float]]]=None)\n", "\n", - "\"Compute forecasts\n", + "*\"Compute forecasts*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", "| h | int | | Number of periods to predict. |\n", "| X_df | Union | None | Dataframe with the future exogenous features. Should have the id column and the time column. |\n", + "| level | Optional | None | Confidence levels between 0 and 100 for prediction intervals. |\n", "| **Returns** | **Union** | | **Predictions for each serie and timestep, with one column per model.** |" ], "text/plain": [ @@ -894,14 +910,16 @@ "### AutoMLForecast.predict\n", "\n", "> AutoMLForecast.predict (h:int, X_df:Union[pandas.core.frame.DataFrame,pol\n", - "> ars.dataframe.frame.DataFrame,NoneType]=None)\n", + "> ars.dataframe.frame.DataFrame,NoneType]=None,\n", + "> level:Optional[List[Union[int,float]]]=None)\n", "\n", - "\"Compute forecasts\n", + "*\"Compute forecasts*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", "| h | int | | Number of periods to predict. |\n", "| X_df | Union | None | Dataframe with the future exogenous features. Should have the id column and the time column. |\n", + "| level | Optional | None | Confidence levels between 0 and 100 for prediction intervals. |\n", "| **Returns** | **Union** | | **Predictions for each serie and timestep, with one column per model.** |" ] }, @@ -931,7 +949,7 @@ "\n", "> AutoMLForecast.save (path:Union[str,pathlib.Path])\n", "\n", - "Save AutoMLForecast objects\n", + "*Save AutoMLForecast objects*\n", "\n", "| | **Type** | **Details** |\n", "| -- | -------- | ----------- |\n", @@ -947,7 +965,7 @@ "\n", "> AutoMLForecast.save (path:Union[str,pathlib.Path])\n", "\n", - "Save AutoMLForecast objects\n", + "*Save AutoMLForecast objects*\n", "\n", "| | **Type** | **Details** |\n", "| -- | -------- | ----------- |\n", @@ -983,7 +1001,7 @@ "> (level:Optional[List[Union[int,flo\n", "> at]]]=None)\n", "\n", - "Access in-sample predictions.\n", + "*Access in-sample predictions.*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -1001,7 +1019,7 @@ "> (level:Optional[List[Union[int,flo\n", "> at]]]=None)\n", "\n", - "Access in-sample predictions.\n", + "*Access in-sample predictions.*\n", "\n", "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", @@ -1095,7 +1113,11 @@ " unique_id\n", " ds\n", " lgb\n", + " lgb-lo-80\n", + " lgb-hi-80\n", " ridge\n", + " ridge-lo-80\n", + " ridge-hi-80\n", " \n", " \n", " \n", @@ -1104,35 +1126,55 @@ " W1\n", " 2180\n", " 35529.435224\n", + " 35061.835362\n", + " 35997.035086\n", " 36110.921202\n", + " 35880.445097\n", + " 36341.397307\n", " \n", " \n", " 1\n", " W1\n", " 2181\n", " 35521.764894\n", + " 34973.035617\n", + " 36070.494171\n", " 36195.175757\n", + " 36051.013811\n", + " 36339.337702\n", " \n", " \n", " 2\n", " W1\n", " 2182\n", " 35537.417268\n", + " 34960.050939\n", + " 36114.783596\n", " 36107.528852\n", + " 35784.062169\n", + " 36430.995536\n", " \n", " \n", " 3\n", " W1\n", " 2183\n", " 35538.058206\n", + " 34823.640706\n", + " 36252.475705\n", " 36027.139248\n", + " 35612.635725\n", + " 36441.642771\n", " \n", " \n", " 4\n", " W1\n", " 2184\n", " 35614.611211\n", + " 34627.023739\n", + " 36602.198683\n", " 36092.858489\n", + " 35389.690977\n", + " 36796.026000\n", " \n", " \n", " ...\n", @@ -1140,62 +1182,99 @@ " ...\n", " ...\n", " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", " \n", " \n", " 4662\n", " W99\n", " 2292\n", " 15071.536978\n", + " 14484.617399\n", + " 15658.456557\n", " 15319.146221\n", + " 14869.410567\n", + " 15768.881875\n", " \n", " \n", " 4663\n", " W99\n", " 2293\n", " 15058.145278\n", + " 14229.686322\n", + " 15886.604234\n", " 15299.549555\n", + " 14584.269352\n", + " 16014.829758\n", " \n", " \n", " 4664\n", " W99\n", " 2294\n", " 15042.493434\n", + " 14096.380636\n", + " 15988.606232\n", " 15271.744712\n", + " 14365.349338\n", + " 16178.140086\n", " \n", " \n", " 4665\n", " W99\n", " 2295\n", " 15042.144846\n", + " 14037.053904\n", + " 16047.235787\n", " 15250.070504\n", + " 14403.428791\n", + " 16096.712216\n", " \n", " \n", " 4666\n", " W99\n", " 2296\n", " 15038.729044\n", + " 13944.821480\n", + " 16132.636609\n", " 15232.127800\n", + " 14325.059776\n", + " 16139.195824\n", " \n", " \n", "\n", - "

4667 rows × 4 columns

\n", + "

4667 rows × 8 columns

\n", "" ], "text/plain": [ - " unique_id ds lgb ridge\n", - "0 W1 2180 35529.435224 36110.921202\n", - "1 W1 2181 35521.764894 36195.175757\n", - "2 W1 2182 35537.417268 36107.528852\n", - "3 W1 2183 35538.058206 36027.139248\n", - "4 W1 2184 35614.611211 36092.858489\n", - "... ... ... ... ...\n", - "4662 W99 2292 15071.536978 15319.146221\n", - "4663 W99 2293 15058.145278 15299.549555\n", - "4664 W99 2294 15042.493434 15271.744712\n", - "4665 W99 2295 15042.144846 15250.070504\n", - "4666 W99 2296 15038.729044 15232.127800\n", - "\n", - "[4667 rows x 4 columns]" + " unique_id ds lgb lgb-lo-80 lgb-hi-80 ridge \\\n", + "0 W1 2180 35529.435224 35061.835362 35997.035086 36110.921202 \n", + "1 W1 2181 35521.764894 34973.035617 36070.494171 36195.175757 \n", + "2 W1 2182 35537.417268 34960.050939 36114.783596 36107.528852 \n", + "3 W1 2183 35538.058206 34823.640706 36252.475705 36027.139248 \n", + "4 W1 2184 35614.611211 34627.023739 36602.198683 36092.858489 \n", + "... ... ... ... ... ... ... \n", + "4662 W99 2292 15071.536978 14484.617399 15658.456557 15319.146221 \n", + "4663 W99 2293 15058.145278 14229.686322 15886.604234 15299.549555 \n", + "4664 W99 2294 15042.493434 14096.380636 15988.606232 15271.744712 \n", + "4665 W99 2295 15042.144846 14037.053904 16047.235787 15250.070504 \n", + "4666 W99 2296 15038.729044 13944.821480 16132.636609 15232.127800 \n", + "\n", + " ridge-lo-80 ridge-hi-80 \n", + "0 35880.445097 36341.397307 \n", + "1 36051.013811 36339.337702 \n", + "2 35784.062169 36430.995536 \n", + "3 35612.635725 36441.642771 \n", + "4 35389.690977 36796.026000 \n", + "... ... ... \n", + "4662 14869.410567 15768.881875 \n", + "4663 14584.269352 16014.829758 \n", + "4664 14365.349338 16178.140086 \n", + "4665 14403.428791 16096.712216 \n", + "4666 14325.059776 16139.195824 \n", + "\n", + "[4667 rows x 8 columns]" ] }, "execution_count": null, @@ -1229,8 +1308,9 @@ " num_samples=2,\n", " optimize_kwargs={'timeout': 60},\n", " fitted=True,\n", + " prediction_intervals=PredictionIntervals(n_windows=2, h=h),\n", ")\n", - "auto_mlf.predict(h)" + "auto_mlf.predict(h, level=[80])" ] }, { @@ -1475,27 +1555,27 @@ " white-space: pre-wrap;\n", "}\n", "\n", - "shape: (4_667, 3)
unique_iddsridge
stri64f64
"W1"218035046.096663
"W1"218134743.269216
"W1"218234489.591086
"W1"218334270.768179
"W1"218434124.021857
"W99"229214719.457096
"W99"229314631.552077
"W99"229414532.905239
"W99"229514446.065443
"W99"229614363.049604
" + "shape: (4_667, 5)
unique_iddsridgeridge-lo-80ridge-hi-80
stri64f64f64f64
"W1"218035046.09666334046.6952136045.498116
"W1"218134743.26921633325.84797536160.690457
"W1"218234489.59108632591.25455936387.927614
"W1"218334270.76817932076.50772736465.02863
"W1"218434124.02185731352.45412136895.589593
"W99"229214719.45709613983.30858215455.605609
"W99"229314631.55207713928.87433615334.229818
"W99"229414532.90523913642.84011815422.97036
"W99"229514446.06544313665.08866715227.04222
"W99"229614363.04960413654.22005115071.879157
" ], "text/plain": [ - "shape: (4_667, 3)\n", - "┌───────────┬──────┬──────────────┐\n", - "│ unique_id ┆ ds ┆ ridge │\n", - "│ --- ┆ --- ┆ --- │\n", - "│ str ┆ i64 ┆ f64 │\n", - "╞═══════════╪══════╪══════════════╡\n", - "│ W1 ┆ 2180 ┆ 35046.096663 │\n", - "│ W1 ┆ 2181 ┆ 34743.269216 │\n", - "│ W1 ┆ 2182 ┆ 34489.591086 │\n", - "│ W1 ┆ 2183 ┆ 34270.768179 │\n", - "│ W1 ┆ 2184 ┆ 34124.021857 │\n", - "│ … ┆ … ┆ … │\n", - "│ W99 ┆ 2292 ┆ 14719.457096 │\n", - "│ W99 ┆ 2293 ┆ 14631.552077 │\n", - "│ W99 ┆ 2294 ┆ 14532.905239 │\n", - "│ W99 ┆ 2295 ┆ 14446.065443 │\n", - "│ W99 ┆ 2296 ┆ 14363.049604 │\n", - "└───────────┴──────┴──────────────┘" + "shape: (4_667, 5)\n", + "┌───────────┬──────┬──────────────┬──────────────┬──────────────┐\n", + "│ unique_id ┆ ds ┆ ridge ┆ ridge-lo-80 ┆ ridge-hi-80 │\n", + "│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n", + "│ str ┆ i64 ┆ f64 ┆ f64 ┆ f64 │\n", + "╞═══════════╪══════╪══════════════╪══════════════╪══════════════╡\n", + "│ W1 ┆ 2180 ┆ 35046.096663 ┆ 34046.69521 ┆ 36045.498116 │\n", + "│ W1 ┆ 2181 ┆ 34743.269216 ┆ 33325.847975 ┆ 36160.690457 │\n", + "│ W1 ┆ 2182 ┆ 34489.591086 ┆ 32591.254559 ┆ 36387.927614 │\n", + "│ W1 ┆ 2183 ┆ 34270.768179 ┆ 32076.507727 ┆ 36465.02863 │\n", + "│ W1 ┆ 2184 ┆ 34124.021857 ┆ 31352.454121 ┆ 36895.589593 │\n", + "│ … ┆ … ┆ … ┆ … ┆ … │\n", + "│ W99 ┆ 2292 ┆ 14719.457096 ┆ 13983.308582 ┆ 15455.605609 │\n", + "│ W99 ┆ 2293 ┆ 14631.552077 ┆ 13928.874336 ┆ 15334.229818 │\n", + "│ W99 ┆ 2294 ┆ 14532.905239 ┆ 13642.840118 ┆ 15422.97036 │\n", + "│ W99 ┆ 2295 ┆ 14446.065443 ┆ 13665.088667 ┆ 15227.04222 │\n", + "│ W99 ┆ 2296 ┆ 14363.049604 ┆ 13654.220051 ┆ 15071.879157 │\n", + "└───────────┴──────┴──────────────┴──────────────┴──────────────┘" ] }, "execution_count": null, @@ -1519,8 +1599,9 @@ " num_samples=2,\n", " optimize_kwargs={'timeout': 60},\n", " fitted=True,\n", + " prediction_intervals=PredictionIntervals(n_windows=2, h=h),\n", ")\n", - "auto_mlf.predict(h)" + "auto_mlf.predict(h, level=[80])" ] }, { @@ -1539,27 +1620,27 @@ " white-space: pre-wrap;\n", "}\n", "\n", - "shape: (362_245, 4)
unique_iddsyridge
stri64f64f64
"W1"141061.961249.326428
"W1"151071.061246.067836
"W1"161073.731254.027897
"W1"171066.971254.475948
"W1"181066.171248.306754
"W99"227915738.5415754.558812
"W99"228015388.1315655.780865
"W99"228115187.6215367.498468
"W99"228215172.2715172.591423
"W99"228315101.0315141.032886
" + "shape: (362_245, 6)
unique_iddsyridgeridge-lo-95ridge-hi-95
stri64f64f64f64f64
"W1"141061.961249.326428488.7652492009.887607
"W1"151071.061246.067836485.5066572006.629015
"W1"161073.731254.027897493.4667182014.589076
"W1"171066.971254.475948493.9147692015.037126
"W1"181066.171248.306754487.7455752008.867933
"W99"227915738.5415754.55881215411.96864516097.148979
"W99"228015388.1315655.78086515313.19069815998.371032
"W99"228115187.6215367.49846815024.90830115710.088635
"W99"228215172.2715172.59142314830.00125615515.18159
"W99"228315101.0315141.03288614798.4427215483.623053
" ], "text/plain": [ - "shape: (362_245, 4)\n", - "┌───────────┬──────┬──────────┬──────────────┐\n", - "│ unique_id ┆ ds ┆ y ┆ ridge │\n", - "│ --- ┆ --- ┆ --- ┆ --- │\n", - "│ str ┆ i64 ┆ f64 ┆ f64 │\n", - "╞═══════════╪══════╪══════════╪══════════════╡\n", - "│ W1 ┆ 14 ┆ 1061.96 ┆ 1249.326428 │\n", - "│ W1 ┆ 15 ┆ 1071.06 ┆ 1246.067836 │\n", - "│ W1 ┆ 16 ┆ 1073.73 ┆ 1254.027897 │\n", - "│ W1 ┆ 17 ┆ 1066.97 ┆ 1254.475948 │\n", - "│ W1 ┆ 18 ┆ 1066.17 ┆ 1248.306754 │\n", - "│ … ┆ … ┆ … ┆ … │\n", - "│ W99 ┆ 2279 ┆ 15738.54 ┆ 15754.558812 │\n", - "│ W99 ┆ 2280 ┆ 15388.13 ┆ 15655.780865 │\n", - "│ W99 ┆ 2281 ┆ 15187.62 ┆ 15367.498468 │\n", - "│ W99 ┆ 2282 ┆ 15172.27 ┆ 15172.591423 │\n", - "│ W99 ┆ 2283 ┆ 15101.03 ┆ 15141.032886 │\n", - "└───────────┴──────┴──────────┴──────────────┘" + "shape: (362_245, 6)\n", + "┌───────────┬──────┬──────────┬──────────────┬──────────────┬──────────────┐\n", + "│ unique_id ┆ ds ┆ y ┆ ridge ┆ ridge-lo-95 ┆ ridge-hi-95 │\n", + "│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n", + "│ str ┆ i64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 │\n", + "╞═══════════╪══════╪══════════╪══════════════╪══════════════╪══════════════╡\n", + "│ W1 ┆ 14 ┆ 1061.96 ┆ 1249.326428 ┆ 488.765249 ┆ 2009.887607 │\n", + "│ W1 ┆ 15 ┆ 1071.06 ┆ 1246.067836 ┆ 485.506657 ┆ 2006.629015 │\n", + "│ W1 ┆ 16 ┆ 1073.73 ┆ 1254.027897 ┆ 493.466718 ┆ 2014.589076 │\n", + "│ W1 ┆ 17 ┆ 1066.97 ┆ 1254.475948 ┆ 493.914769 ┆ 2015.037126 │\n", + "│ W1 ┆ 18 ┆ 1066.17 ┆ 1248.306754 ┆ 487.745575 ┆ 2008.867933 │\n", + "│ … ┆ … ┆ … ┆ … ┆ … ┆ … │\n", + "│ W99 ┆ 2279 ┆ 15738.54 ┆ 15754.558812 ┆ 15411.968645 ┆ 16097.148979 │\n", + "│ W99 ┆ 2280 ┆ 15388.13 ┆ 15655.780865 ┆ 15313.190698 ┆ 15998.371032 │\n", + "│ W99 ┆ 2281 ┆ 15187.62 ┆ 15367.498468 ┆ 15024.908301 ┆ 15710.088635 │\n", + "│ W99 ┆ 2282 ┆ 15172.27 ┆ 15172.591423 ┆ 14830.001256 ┆ 15515.18159 │\n", + "│ W99 ┆ 2283 ┆ 15101.03 ┆ 15141.032886 ┆ 14798.44272 ┆ 15483.623053 │\n", + "└───────────┴──────┴──────────┴──────────────┴──────────────┴──────────────┘" ] }, "execution_count": null, @@ -1569,7 +1650,7 @@ ], "source": [ "#| polars\n", - "auto_mlf.forecast_fitted_values()" + "auto_mlf.forecast_fitted_values(level=[95])" ] } ],