Turning a time series into features a model can learn from.
lag steps away, so
lag steps.
Mind the sign: lag=-1 looks backwards, at the previous value, and is almost always what you want. A positive lag looks forward, feeding the model a value from the future — which trains beautifully and predicts nothing. Both transformers default to lag=-1.
Shifting leaves boundary rows with no value to draw on. By default those are filled with NaN and the row count is preserved; pass fill_with_missing=False to drop them instead.
Evaluate with TimeSeriesSplit. Lagged features make a shuffled split leak outright: a training row can hold the very value a test row is being asked to predict.
>>> import numpy as np
>>> from tuiml.preprocessing.timeseries import LagTransformer
>>> X = np.arange(5, dtype=float).reshape(-1, 1)
>>> LagTransformer(lag=-1, columns=[0], fill_with_missing=False).fit_transform(X).ravel().tolist()
[0.0, 1.0, 2.0, 3.0]