Back to models
Transformer

WindowSummarizer

Transformer for extracting time series features.

Quickstart

python
from sktime.transformations.summarize import WindowSummarizer

estimator = WindowSummarizer(lag_feature=None, n_jobs=-1, target_cols=None, truncate=None)

Parameters(3)

n_jobsint, optional (default=-1)

The number of jobs to run in parallel for applying the window functions. -1 means using all processors.

target_cols: list of str, optional (default = None)

Specifies which columns in X to target for applying the window functions. None will target the first column

lag_feature: dict of str and list, optional (default = dict containing first lag)

Dictionary specifying as key the type of function to be used and as value the argument window. For the function lag, the argument window is an integer or a list of integers giving the lag values to be used. For all other functions, the argument window is a list with the arguments lag and window length. lag defines how far back in the past the window starts, window length gives the length of the window across which to apply the function. For multiple different windows, provide a list of lists.

Please see below a graphical representation of the logic using the following symbols:

z = time stamp that the window is summarized to.

Part of the window if lag is between 0 and 1-window_length, otherwise not part of the window.

x = (other) time stamps in the window which is summarized

* = observations, past or future, not part of the window

The summarization function is applied to the window consisting of x and potentially z.

For window = [1, 3], we have a lag of 1 and window_length of 3 to target the three last days (exclusive z) that were observed. Summarization is done across windows like this:

|---------------------------| | * * * * * * * * x x x z * | |---------------------------|

For window = [0, 3], we have a lag of 0 and window_length of 3 to target the three last days (inclusive z) that were observed. Summarization is done across windows like this:

|---------------------------| | * * * * * * * * x x z * * | |---------------------------|

Special case lag: Since lags are frequently used and window length is redundant, you only need to provide a list of lag values. So window = [1] will result in the first lag:

|---------------------------| | * * * * * * * * * * x z * | |---------------------------|

And window = [1, 4] will result in the first and fourth lag:

|---------------------------| | * * * * * * * x * * x z * | |---------------------------| key: either custom function call (to be provided by user) or str corresponding to native pandas window function:
  • “sum”,

  • “mean”,

  • “median”,

  • “std”,

  • “var”,

  • “kurt”,

  • “min”,

  • “max”,

  • “corr”,

  • “cov”,

  • “skew”,

  • “sem”

See also: https://pandas.pydata.org/docs/reference/window.html.

Examples

>>> import pandas as pd
>>> from sktime.transformations.summarize import WindowSummarizer
>>> from sktime.datasets import load_airline, load_longley
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.forecasting.base import ForecastingHorizon
>>> from sktime.forecasting.compose import ForecastingPipeline
>>> from sktime.split import temporal_train_test_split
>>> y = load_airline ()
>>> kwargs = {
... "lag_feature": {
... "lag": [1 ],
... "mean": [[1, 3 ], [3, 6 ]],
... "std": [[1, 4 ]],
... }
... }
>>> transformer = WindowSummarizer (** kwargs)
>>> y_transformed = transformer. fit_transform (y) Example with transforming multiple columns of exogenous features
>>> y, X = load_longley ()
>>> y_train, y_test, X_train, X_test = temporal_train_test_split (y, X)
>>> fh = ForecastingHorizon (X_test. index, is_relative = False)
>>> # Example transforming only X
>>> pipe = ForecastingPipeline (
... steps = [
... ("a", WindowSummarizer (n_jobs = 1, target_cols = ["POP", "GNPDEFL" ])),
... ("b", WindowSummarizer (n_jobs = 1, target_cols = ["GNP" ], ** kwargs)),
... ("forecaster", NaiveForecaster (strategy = "drift")),
... ]
... )
>>> pipe_return = pipe. fit (y_train, X_train)
>>> y_pred1 = pipe_return. predict (fh = fh, X = X_test) Example with transforming multiple columns of exogenous features as well as the y column
>>> Z_train = pd. concat ([X_train, y_train ], axis = 1)
>>> Z_test = pd. concat ([X_test, y_test ], axis = 1)
>>> pipe = ForecastingPipeline (
... steps = [
... ("a", WindowSummarizer (n_jobs = 1, target_cols = ["POP", "TOTEMP" ])),
... ("b", WindowSummarizer (** kwargs, n_jobs = 1, target_cols = ["GNP" ])),
... ("forecaster", NaiveForecaster (strategy = "drift")),
... ]
... )
>>> pipe_return = pipe. fit (y_train, Z_train)
>>> y_pred2 = pipe_return. predict (fh = fh, X = Z_test)