Back to models
Forecaster

GroupbyCategoryForecaster

Categorical in XInsamplePred int insampleExogenousMultivariate

Choosing a global forecaster based on category or cluster of time series.

Quickstart

python
from sktime.forecasting.compose import GroupbyCategoryForecaster

estimator = GroupbyCategoryForecaster(forecasters, transformer=None, fallback_forecaster=None)

Parameters(3)

forecastersdict[sktime forecasters]
dict of forecasters with the key corresponding to categories generated by the given transformer and the value corresponding to a sktime forecaster.
transformersktime transformer or clusterer, default = ADICVTransformer()

A series-to-primitives sktime transformer that generates a value which can be used to quantify a choice of forecaster for the time series.

If a clusterer is used, it must support cluster assignment, i.e, have the capability:predict tag.

Note: To ensure correct functionality, the transformer must store the generated category in the first column of the returned values when the transform() or fit_transform() functions are called.

fallback_forecastersktime forecaster | None, Optional
A fallback forecaster that will be used if the category generated by the transformer does not match any of the given forecasters.

Examples

This example showcases how the GroupbyCategoryForecaster can be utilized to select appropriate forecasters on the basis of the time series category determined by the ADICVTransformer:
>>> from sktime.forecasting.compose import GroupbyCategoryForecaster
>>> from sktime.forecasting.croston import Croston
>>> from sktime.forecasting.trend import PolynomialTrendForecaster
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.transformations.adi_cv import ADICVTransformer Importing the methods which can generate data of specific categories depending on their variance and average demand intervals.
>>> from sktime.transformations.tests.test_adi_cv import (
... _generate_erratic_series) The forecaster is defined which accepts a dictionary of forecasters, a transformer and optionally a fallback_forecaster
>>> group_forecaster = GroupbyCategoryForecaster (
... forecasters =
... { "smooth": NaiveForecaster (),
... "erratic": PolynomialTrendForecaster (),
... "intermittent": Croston ()},
... transformer = ADICVTransformer (features = ["class" ]))
>>> generated_data = _generate_erratic_series () The fit function firstly passes the data through the given transformer to generate a given category. This category can be seen by the variable self.category_.
>>> group_forecaster = group_forecaster. fit (generated_data, fh = 50)
>>> #print(f"The chosen category is: {group_forecaster.category}")
>>> # Print out the predicted value over the given forecasting horizon!
>>> # print(group_forecaster.predict(fh=50, X=None))