Zurück zu den Modellen
Forecaster

FhPlexForecaster

Uses different parameters by forecasting horizon element.

When provided with forecasting horizon [f1, f2, …, fn], will fit forecaster with fh=f1 and parameters fh_params[f1] to forecast f1, forecaster with fh=f2 and parameters fh_params[f2] to forecast f2, etc.

To use different estimators per horizon, combine FhPlexForecaster with one of MultiplexForecaster and MultiplexTransformer.

Schnellstart

python
from sktime.forecasting.compose import FhPlexForecaster

estimator = FhPlexForecaster(forecaster, fh_params=None, fh_lookup='relative', fh_contiguous=False)

Parameter(4)

forecastersktime compatible forecaster
fh_paramsdict, list, callable, or str that eval-defines a callable

specifies forecaster to use per fh element

  • dict: keys = fh elements, values = param dict for forecaster

  • list: i-th entry is forecaster param dict for i-th fh element

  • callable: maps fh element to forecaster param dict

  • str: eval(fh_params) must define a lambda that maps fh element to param dict

param dict need not be complete, only overrides for forecaster params

fh_lookupstr, one of “relative” (default), “absolute”, or “as-is”

specifies fh elements used in dict or callable

  • if “relative”, fh will be coerced to relative ForecastingHorizon

  • if “absolute”, fh will be coerced to absolute ForecastingHorizon

  • if “as-is”, fh will be coerced to ForecastingHorizon (but not relative/absolute)

fh_contiguousbool, default=False

whether fh in inner loops are enforced to be contiguous

  • False: forecaster with fh_params[fN] is asked to forecast fN and only fN

  • True: forecaster with fh_params[fN] is asked to forecast 1, 2, …, fN and the output is then subset to the forecast of fN this is required if the forecaster can only forecast contiguous horizons

CAUTION: if using grid search inside, then True will cause the tuning metric to be evaluated on horizons 1, 2, …, fN, not just fN

Beispiele

>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.forecasting.compose import FhPlexForecaster Simple example - same parameters per fh element
>>> y = load_airline()
>>> f = FhPlexForecaster(NaiveForecaster())
>>> f.fit(y, fh=[1, 2, 3]) FhPlexForecaster(…)
>>> # get individual fitted forecasters
>>> f.forecasters_ # doctest: +SKIP {1: NaiveForecaster(), 2: NaiveForecaster(), 3: NaiveForecaster()}
>>> fitted_params = f.get_fitted_params() # or via get_fitted_params
>>> y_pred = f.predict() Simple example - different parameters per fh element
>>> y = load_airline()
>>> fh_params = [{}, {“strategy”: “last”}, {“strategy”: “mean”}]
>>> f = FhPlexForecaster(NaiveForecaster(), fh_params=fh_params)
>>> f.fit(y, fh=[1, 2, 3]) FhPlexForecaster(…)
>>> # get individual fitted forecasters
>>> f.forecasters_ # doctest: +SKIP {1: NaiveForecaster(), 2: NaiveForecaster(), 3: NaiveForecaster(strategy=’mean’)}
>>> y_pred = f.predict()