Skip to content

STLBootstrapTransformer

STLBootstrapTransformer

class STLBootstrapTransformer(n_series: int = 10, sp: int = 12, block_length: int = None, sampling_replacement: bool = False, return_actual: bool = True, lambda_bounds: tuple = None, lambda_method: str = 'guerrero', seasonal: int = 7, trend: int = None, low_pass: int = None, seasonal_deg: int = 1, trend_deg: int = 1, low_pass_deg: int = 1, robust: bool = False, seasonal_jump: int = 1, trend_jump: int = 1, low_pass_jump: int = 1, inner_iter: int = None, outer_iter: int = None, random_state: int | RandomState = None, return_indices=False)[source]

Creates a population of similar time series.

This method utilises a form of bootstrapping to generate a population of similar time series to the input time series [1], [2].

First the observed time series is transformed using a Box-Cox transformation to stabilise the variance. Then it’s decomposed to seasonal, trend and residual time series, using the STL implementation from statsmodels (statsmodels.tsa.api.STL) [4]. We then sample blocks from the residuals time series using the Moving Block Bootstrapping (MBB) method [3] to create synthetic residuals series that mimic the autocorrelation patterns of the observed series. Finally these bootstrapped residuals are added to the season and trend components and we use the inverse Box-Cox transform to return a panel of similar time series. The output can be used for bagging forecasts, prediction intervals and data augmentation.

The returned panel will be a multiindex dataframe (pd.DataFrame) with the series_id and time_index as the index and a single column of the time series value. The values for series_id are “actual” for the original series and “synthetic_n” (where n is an integer) for the generated series. See the Examples section for example output.

Parameters:
n_seriesint, optional

The number of bootstrapped time series that will be generated, by default 10.

spint, optional

Seasonal periodicity of the data in integer form, by default 12. Must be an integer >= 2

block_lengthint, optional

The length of the block in the MBB method, by default None. If not provided, the following heuristic is used, the block length will the minimum between 2*sp and len(X) - sp.

sampling_replacementbool, optional

Whether the MBB sample is with or without replacement, by default False.

return_actualbool, optional

If True the output will contain the actual time series, by default True. The actual time series will be labelled as “<series_name>_actual” (or “actual” if series name is None).

lambda_boundsTuple, optional

BoxCox parameter: Lower and upper bounds used to restrict the feasible range when solving for the value of lambda, by default None.

lambda_methodstr, optional

BoxCox parameter: {“pearsonr”, “mle”, “all”, “guerrero”}, by default “guerrero”. The optimization approach used to determine the lambda value used in the Box-Cox transformation.

seasonalint, optional

STL parameter: Length of the seasonal smoother. Must be an odd integer, and should normally be >= 7, by default 7.

trendint, optional

STL parameter: Length of the trend smoother, by default None. 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_passint, optional

STL parameter: Length of the low-pass filter, by default None. Must be an odd integer >=3. If not provided, uses the smallest odd integer > period

seasonal_degint, optional

STL parameter: Degree of seasonal LOESS. 0 (constant) or 1 (constant and trend), by default 1.

trend_degint, optional

STL parameter: Degree of trend LOESS. 0 (constant) or 1 (constant and trend), by default 1.

low_pass_degint, optional

STL parameter: Degree of low pass LOESS. 0 (constant) or 1 (constant and trend), by default 1.

robustbool, optional

STL parameter: Flag indicating whether to use a weighted version that is robust to some forms of outliers, by default False.

seasonal_jumpint, optional

STL parameter: Positive integer determining the linear interpolation step, by default 1. 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, optional

STL parameter: Positive integer determining the linear interpolation step, by default 1. 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, optional

STL parameter: Positive integer determining the linear interpolation step, by default 1. 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_iterint, optional

STL parameter: Number of iterations to perform in the inner loop, by default None. If not provided uses 2 if robust is True, or 5 if not. This param goes into STL.fit() from statsmodels.

outer_iterint, optional

STL parameter: Number of iterations to perform in the outer loop, by default None. If not provided uses 15 if robust is True, or 0 if not. This param goes into STL.fit() from statsmodels.

random_stateint, np.random.RandomState or None, by default None

Controls the randomness of the estimator

return_indicesbool, optional

If True, the output will contain the resampled indices as extra column, by default False.

Attributes:
is_fitted

Whether fit has been called.

See also

sktime.transformations.bootstrap.MovingBlockBootstrapTransformer

Transformer that applies the Moving Block Bootstrapping method to create a panel of synthetic time series.

References

[1]

Bergmeir, C., Hyndman, R. J., & Benítez, J. M. (2016). Bagging exponential smoothing methods using STL decomposition and Box-Cox transformation. International Journal of Forecasting, 32(2), 303-312

[2]

Hyndman, R.J., & Athanasopoulos, G. (2021) Forecasting: principles and practice, 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3, Chapter 12.5. Accessed on February 13th 2022.

[3]

Kunsch HR (1989) The jackknife and the bootstrap for general stationary observations. Annals of Statistics 17(3), 1217-1241

Examples

>>> from sktime.transformations.bootstrap import STLBootstrapTransformer
>>> from sktime.datasets import load_airline
>>> from sktime.utils.plotting import plot_series
>>> y = load_airline()
>>> transformer = STLBootstrapTransformer(10)
>>> y_hat = transformer.fit_transform(y)
>>> series_list = []
>>> names = []
>>> for group, series in y_hat.groupby(level=0, as_index=False):
...     series.index = series.index.droplevel(0)
...     series_list.append(series)
...     names.append(group)
>>> plot_series(*series_list, labels=names)
(...)
>>> print(y_hat.head())
                      Number of airline passengers
series_id time_index
actual    1949-01                            112.0
          1949-02                            118.0
          1949-03                            132.0
          1949-04                            129.0
          1949-05                            121.0

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X[, y])

Fit transformer to X, optionally to y.

fit_transform(X[, y])

Fit to data, then transform it.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

inverse_transform(X[, y])

Inverse transform X and return an inverse transformed version.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

transform(X[, y])

Transform X and return a transformed version.

update(X[, y, update_params])

Update transformer with X, optionally y.