STLForecasterSKTimeWrapper
Python template · sinapsis_sktime.templates.sktime_forecasters
Overview
This template specifically handles sktime series forecasting tasks.
The goal is to train a model and predict future values of the input time series.
Attributes: WrapperEntry (WrapperEntryConfig): Configuration for dynamic template generation TASK_TYPE (str): The type of task (forecasting) CATEGORY (str): The category of the template AttributesBaseModel: Reference to the attributes' model class
STLForecaster — inherited documentation
Implements STLForecaster based on statsmodels.tsa.seasonal.STL implementation.
The STLForecaster applies the following algorithm, also see [1]_.
In ``fit``:
1. Use ``statsmodels`` ``STL`` [2]_ to decompose the given series ``y`` into the three components: ``trend``, ``season`` and ``residuals``. 2. Fit clones of ``forecaster_trend`` to ``trend``, ``forecaster_seasonal`` to ``season``, and ``forecaster_resid`` to ``residuals``, using ``y``, ``X``, ``fh`` from ``fit``. The forecasters are fitted as clones, stored in the attributes ``forecaster_trend_``, ``forecaster_seasonal_``, ``forecaster_resid_``.
In ``predict``, forecasts as follows:
1. Obtain forecasts ``y_pred_trend`` from ``forecaster_trend_``, ``y_pred_seasonal`` from ``forecaster_seasonal_``, and ``y_pred_residual`` from ``forecaster_resid_``, using ``X``, ``fh``, from ``predict``. 2. Recompose ``y_pred`` as ``y_pred = y_pred_trend + y_pred_seasonal + y_pred_residual`` 3. Return ``y_pred``
``update`` refits entirely, i.e., behaves as ``fit`` on all data seen so far.
Parameters ---------- sp : int, optional, default=2. Passed to ``statsmodels`` ``STL``. Length of the seasonal period passed to ``statsmodels`` ``STL``. (forecaster_seasonal, forecaster_resid) that are None. The default forecaster_trend does not get sp as trend is independent to seasonality. seasonal : int, optional., default=7. Passed to ``statsmodels`` ``STL``. Length of the seasonal smoother. Must be an odd integer >=3, and should normally be >= 7 (default). trend : {int, None}, optional, default=None. Passed to ``statsmodels`` ``STL``. Length of the trend smoother. Must be an odd integer. If not provided uses the smallest odd integer greater than 1.5 * period / (1 - 1.5 / seasonal), following the suggestion in the original implementation. low_pass : {int, None}, optional, default=None. Passed to ``statsmodels`` ``STL``. Length of the low-pass filter. Must be an odd integer >=3. If not provided, uses the smallest odd integer > period. seasonal_deg : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Degree of seasonal LOESS. 0 (constant) or 1 (constant and trend). trend_deg : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Degree of trend LOESS. 0 (constant) or 1 (constant and trend). low_pass_deg : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Degree of low pass LOESS. 0 (constant) or 1 (constant and trend). robust : bool, optional, default=False. Passed to ``statsmodels`` ``STL``. Flag indicating whether to use a weighted version that is robust to some forms of outliers. seasonal_jump : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Positive integer determining the linear interpolation step. If larger than 1, the LOESS is used every seasonal_jump points and linear interpolation is between fitted points. Higher values reduce estimation time. trend_jump : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Positive integer determining the linear interpolation step. If larger than 1, the LOESS is used every trend_jump points and values between the two are linearly interpolated. Higher values reduce estimation time. low_pass_jump : int, optional, default=1. Passed to ``statsmodels`` ``STL``. Positive integer determining the linear interpolation step. If larger than 1, the LOESS is used every low_pass_jump points and values between the two are linearly interpolated. Higher values reduce estimation time. inner_iter: int or None, optional, default=None. Passed to ``statsmodels`` ``STL``. Number of iterations to perform in the inner loop. If not provided uses 2 if robust is True, or 5 if not. This param goes into STL.fit() from statsmodels. outer_iter: int or None, optional, default=None. Passed to ``statsmodels`` ``STL``. Number of iterations to perform in the outer loop. If not provided uses 15 if robust is True, or 0 if not. This param goes into STL.fit() from statsmodels. forecaster_trend : sktime forecaster, optional Forecaster to be fitted on trend_ component of the STL, by default None. If None, then a NaiveForecaster(strategy="drift") is used. forecaster_seasonal : sktime forecaster, optional Forecaster to be fitted on seasonal_ component of the STL, by default None. If None, then a NaiveForecaster(strategy="last") is used. forecaster_resid : sktime forecaster, optional Forecaster to be fitted on resid_ component of the STL, by default None. If None, then a NaiveForecaster(strategy="mean") is used.
Attributes ---------- trend_ : pd.Series Trend component. seasonal_ : pd.Series Seasonal component. resid_ : pd.Series Residuals component. forecaster_trend_ : sktime forecaster Fitted trend forecaster. forecaster_seasonal_ : sktime forecaster Fitted seasonal forecaster. forecaster_resid_ : sktime forecaster Fitted residual forecaster.
Examples -------- >>> from sktime.datasets import load_airline >>> from sktime.forecasting.trend import STLForecaster >>> y = load_airline() >>> forecaster = STLForecaster(sp=12) # doctest: +SKIP >>> forecaster.fit(y) # doctest: +SKIP STLForecaster(...) >>> y_pred = forecaster.predict(fh=[1,2,3]) # doctest: +SKIP
See Also -------- Deseasonalizer Detrender
References ---------- .. [1] R. B. Cleveland, W. S. Cleveland, J.E. McRae, and I. Terpenning (1990) STL: A Seasonal-Trend Decomposition Procedure Based on LOESS. Journal of Official Statistics, 6, 3-73. .. [2] https://www.statsmodels.org/dev/generated/statsmodels.tsa.seasonal.STL.html
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-sktime==1.0.0uv pip install sinapsis-sktime==1.0.0uv add sinapsis-sktime==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Optional
Default: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
Number of steps ahead to forecast. Defaults to 37. stlforecaster_init sp <class 'int'>: default: 2 seasonal <class 'int'>: default: 7 trend typing.Union[str, typing.Any, NoneType]: default: None low_pass… Read full field description
Number of steps ahead to forecast. Defaults to 37. stlforecaster_init sp <class 'int'>: default: 2 seasonal <class 'int'>: default: 7 trend typing.Union[str, typing.Any, NoneType]: default: None low_pass typing.Union[str, typing.Any, NoneType]: default: None seasonal_deg <class 'int'>: default: 1 trend_deg <class 'int'>: default: 1 low_pass_deg <class 'int'>: default: 1 robust <class 'bool'>: default: False seasonal_jump <class 'int'>: default: 1 trend_jump <class 'int'>: default: 1 low_pass_jump <class 'int'>: default: 1 inner_iter typing.Optional[int]: default: None outer_iter typing.Optional[int]: default: None forecaster_trend <class 'NoneType'>: default: None forecaster_seasonal <class 'NoneType'>: default: None forecaster_resid <class 'NoneType'>: default: None
Optional
Default: 37
Required
Default: null
Required
Default: null
Optional
Default: 2
Optional
Default: null
Optional
Default: false
Optional
Default: null
Optional
Default: 7
Optional
Default: 1
Optional
Default: null
Optional
Default: null
Optional
Default: 1
Optional
Default: 1
Optional
Default: 1
Optional
Default: 1
Optional
Default: 1
Optional
Default: null
Optional
Default: null
Optional
Default: null
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "STLForecasterSKTimeWrapper"
class_name: "STLForecasterSKTimeWrapper"
attributes:
root_dir: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
n_steps_ahead: 37
model_save_path: "<required>"
stlforecaster_init:
sp: 2
trend: null
robust: false
low_pass: null
seasonal: 7
trend_deg: 1
inner_iter: null
outer_iter: null
trend_jump: 1
low_pass_deg: 1
seasonal_deg: 1
low_pass_jump: 1
seasonal_jump: 1
forecaster_resid: null
forecaster_trend: null
forecaster_seasonal: null
Inheritance
sinapsis_sktime.templates.sktime_forecasters.SKTimeTrendForecasterEnvironment variables
Environment definitions belong to their canonical Python modules.