Forecaster
TransformSelectForecaster
Choosing a forecaster based on category or cluster of time series.
Quickstart
python
from sktime.forecasting.compose import TransformSelectForecaster
estimator = TransformSelectForecaster(forecasters, transformer=None, fallback_forecaster=None)Parameters(4)
- 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 sk-time 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:predicttag.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.
- poolingstr, optional, default = “local”, one of {“local”, “global”}
- The pooling strategy to use for the forecasters. If “local”, the forecasters are fit and predicted independently for each category. If “global”, the forecasters are fit and predicted on the entire dataset.
Examples
This example showcases how the TransformSelectForecaster can be utilized to select appropriate forecasters on the basis of the time series category determined by the ADICVTransformer!
>>> from sktime.forecasting.compose._transform_select_forecaster import (
... TransformSelectForecaster)
>>> 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 = TransformSelectForecaster (
... 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))