Back to models
Transformer

STLTransformer

Inverse transformUnequal length

Remove seasonal components from a time-series using STL.

Interfaces statsmodels.tsa.seasonal.STL as an sktime transformer.

STLTransformer can be used to perform deseasonalization or decomposition:

If return_components=False, it will return the deseasonalized series, i.e., the trend component from statsmodels STL.

If return_components=True, it will transform the series into a decomposition of component, returning the trend, seasonal, and residual components.

STLTransformer performs inverse_transform by summing any components, and can be used for pipelining in a TransformedTargetForecaster.

Important: for separate forecasts of trend and seasonality, and an inverse transform that respects seasonality, ensure that return_components=True is set, otherwise the inverse will just return the trend component.

An alternative for pipeline-style composition is STLForecaster.

Quickstart

python
from sktime.transformations.detrend import STLTransformer

estimator = STLTransformer(sp=2, seasonal=7, trend=None, low_pass=None, seasonal_deg=1, trend_deg=1, low_pass_deg=1, robust=False, seasonal_jump=1, trend_jump=1, low_pass_jump=1, return_components=False)

Parameters(12)

spint, default=1
Seasonal periodicity.
seasonalint, default=7
Length of the seasonal smoother. Must be an odd integer, and should normally be >= 7 (default).
trend{int, default=None}
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, default=None}
Length of the low-pass filter. Must be an odd integer >=3. If not provided, uses the smallest odd integer > period.
seasonal_degint, default=1
Degree of seasonal LOESS. 0 (constant) or 1 (constant and trend).
trend_degint, default=1
Degree of trend LOESS. 0 (constant) or 1 (constant and trend).
low_pass_degint, default=1
Degree of low pass LOESS. 0 (constant) or 1 (constant and trend).
robustbool, default False
Flag indicating whether to use a weighted version that is robust to some forms of outliers.
seasonal_jumpint, default=1
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_jumpint, default=1
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_jumpint, default=1
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.
return_componentsbool, default=False

if False, will return only the trend component if True, will return the transformed series, as well as three components

as variables in the returned multivariate series (DataFrame cols) “transformed” - the transformed series “seasonal” - the seasonal component “trend” - the trend component “resid” - the residuals after de-trending, de-seasonalizing

Examples

>>> from sktime.datasets import load_airline
>>> from sktime.transformations.detrend import STLTransformer
>>> X = load_airline ()
>>> transformer = STLTransformer (sp = 12)
>>> Xt = transformer. fit_transform (X)

References