Differencer
Apply iterative differences to a timeseries.
The transformation works for univariate and multivariate timeseries. However, the multivariate case applies the same differencing to every series.
Difference transformations are applied at the specified lags in the order provided.
For example, given a timeseries with monthly periodicity, using lags=[1, 12] corresponds to applying a standard first difference to handle trend, and followed by a seasonal difference (at lag 12) to attempt to account for seasonal dependence.
To provide a higher-order difference at the same lag list the lag multiple times. For example, lags=[1, 1] takes iterative first differences like may be needed for a series that is integrated of order 2.
Schnellstart
from sktime.transformations.difference import Differencer
estimator = Differencer(lags=1, na_handling='fill_zero', memory='all')Parameter(3)
- lagsint or array-like, default = 1
The lags used to difference the data. If a single
intvalue is- na_handlingstr, optional, default = “fill_zero”
How to handle the NaNs that appear at the start of the series from differencing Example: there are only 3 differences in a series of length 4,
differencing [a, b, c, d] gives [?, b-a, c-b, d-c] so we need to determine what happens with the “?” (= unknown value)
“drop_na” - unknown value(s) are dropped, the series is shortened “keep_na” - unknown value(s) is/are replaced by NaN “fill_zero” - unknown value(s) is/are replaced by zero
- memorystr, optional, default = “all”
how much of previously seen X to remember, for exact reconstruction of inverse “all”: estimator remembers all X, inverse is correct for all indices seen “latest”: estimator only remembers latest X necessary for future reconstruction
inverses at any time stamps after fit are correct, but not past time stamps
“none”: estimator does not remember any X, inverse is direct cumsum
Beispiele
>>> from sktime.transformations.difference import Differencer
>>> from sktime.datasets import load_airline
>>> y = load_airline ()
>>> transformer = Differencer (lags = [1, 12 ])
>>> y_transform = transformer. fit_transform (y)