Skip to content

STLForecaster

STLForecaster

class STLForecaster(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, inner_iter=None, outer_iter=None, forecaster_trend=None, forecaster_seasonal=None, forecaster_resid=None)[source]

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:
spint, 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.

seasonalint, 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_degint, optional, default=1. Passed to statsmodels STL.

Degree of seasonal LOESS. 0 (constant) or 1 (constant and trend).

trend_degint, optional, default=1. Passed to statsmodels STL.

Degree of trend LOESS. 0 (constant) or 1 (constant and trend).

low_pass_degint, optional, default=1. Passed to statsmodels STL.

Degree of low pass LOESS. 0 (constant) or 1 (constant and trend).

robustbool, optional, default=False. Passed to statsmodels STL.

Flag indicating whether to use a weighted version that is robust to some forms of outliers.

seasonal_jumpint, 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_jumpint, 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_jumpint, 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_trendsktime 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_seasonalsktime 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_residsktime 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.

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.

Examples

>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.trend import STLForecaster
>>> y = load_airline()
>>> forecaster = STLForecaster(sp=12)
>>> forecaster.fit(y)
STLForecaster(...)
>>> y_pred = forecaster.predict(fh=[1,2,3])

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(y[, X, fh])

Fit forecaster to training data.

fit_predict(y[, X, fh, X_pred])

Fit and forecast time series at future horizon.

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_pretrained_params([deep])

Get pretrained parameters of this estimator.

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.

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.

plot_components([title])

Plot the observed, trend, seasonal, and residual components.

predict([fh, X])

Forecast time series at future horizon.

predict_interval([fh, X, coverage])

Compute/return prediction interval forecasts.

predict_proba([fh, X, marginal])

Compute/return fully probabilistic forecasts.

predict_quantiles([fh, X, alpha])

Compute/return quantile forecasts.

predict_residuals([y, X])

Return residuals of time series forecasts.

predict_var([fh, X, cov])

Compute/return variance forecasts.

pretrain(y[, X, fh])

Pre-train forecaster on panel (global) data.

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.

score(y[, X, fh])

Scores forecast against ground truth, using MAPE (non-symmetric).

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.

update(y[, X, update_params])

Update cutoff value and, optionally, fitted parameters.

update_predict(y[, cv, X, update_params, ...])

Make predictions and update model iteratively over the test set.

update_predict_single([y, fh, X, update_params])

Update model with new data and make forecasts.