LagTransformer¶
yohou.preprocessing.window.LagTransformer
¶
Bases: BaseTransformer
Create lagged features from time series data.
Creates lagged versions of each feature column, where each lag shifts the data by a specified number of time steps. This is essential for time series forecasting using supervised learning approaches.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
lag
|
int >= 1 or list of ints >= 1
|
Lag(s) to create. Can be a single integer or a list of integers. Each lag value must be >= 1. |
1
|
Attributes¶
| Name | Type | Description |
|---|---|---|
lags_ |
list of int
|
Effective list of lags used for transformation. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import LagTransformer
>>> # Create sample data
>>> X = pl.DataFrame({
... "time": [datetime(2020, 1, i) for i in range(1, 11)],
... "value": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
... })
>>> # Create lag-1 and lag-2 features
>>> transformer = LagTransformer(lag=[1, 2])
>>> transformer.fit(X)
LagTransformer(...)
>>> X_lagged = transformer.transform(X)
>>> X_lagged.columns
['time', 'value_lag_1', 'value_lag_2']
>>> len(X_lagged) # First 2 rows dropped (max(lag) = 2)
8
See Also¶
MeanLagTransformer : Averages multiple lag multiples into a single feature.
RollingStatisticsTransformer : Compute rolling statistics (mean, std, etc.).
SlidingWindowFunctionTransformer : Apply custom functions to sliding windows.
tabularize : Underlying tabularization function.
Notes¶
Lag features are created using yohou.utils.tabularization.tabularize,
which shifts each numeric column by the specified number of time steps.
The first max(lags) rows are dropped because they contain incomplete
lag values, setting observation_horizon = max(lags).
When used inside a pipeline with observe/rewind, the observation
buffer retains enough history to produce lag features without data loss
on subsequent transform calls.
Source Code¶
Show/Hide source
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
Methods¶
observation_horizon
property
¶
Return the number of past observations needed.
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
array-like of str or None
|
Column names of the input features. If |
None
|
Returns¶
| Type | Description |
|---|---|
list of str
|
Output feature names after transformation. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Tune Fourier Seasonality Terms
Data-Features
Explore how Fourier harmonic count affects seasonal fit quality, compare Fourier vs Pattern seasonality, and tune harmonics jointly with GridSearchCV.
-
How to Handle Long Series
Data-Features
Limit history with observation_horizon, weight recent errors with exponential decay, and downsample high-frequency data.
-
How to Aggregate Scorer Results
Evaluation-Search
Demonstrate all scorer aggregation strategies (stepwise, vintagewise, componentwise, groupwise, coveragewise, all) on panel data with weighted group aggregation.
-
How to Forecast with CatBoost
Forecasting-Models
Plug CatBoostRegressor into PointReductionForecaster as a drop-in sklearn estimator, compare gradient-boosted versus Ridge linear baseline, and demonstrate the direct reduction strategy with tree-based models.
-
How to Choose a Decomposition Strategy
Forecasting-Models
Build 2- and 3-component DecompositionPipeline forecasters chaining trend, seasonality, and residual models with target pre-transformation.
-
How to Use Lagged Forecasts as Features
Forecasting-Models
Compare ForecastedFeatureForecaster strategies (actual, predicted, rewind) and split ratio tuning for chaining feature and target forecasters.
-
How to Configure LocalPanelForecaster
Panel-Data
Wrap any forecaster with LocalPanelForecaster for fully independent per-group clones, parallel fitting via n_jobs, and selective group operations.
-
How to Run Panel Cross-Validation
Panel-Data
Time series cross-validation on panel data with GridSearchCV, selective group observation, rewind operations, and groupwise performance comparison.
-
How to Forecast Panel Prediction Intervals
Panel-Data
Combine conformal and quantile regression intervals on panel data with per-group coverage analysis, calibration plots, and groupwise interval scoring.
-
How to Apply Stationarity to Panel Data
Panel-Data
Apply per-group stationarity transforms on panel data with SeasonalDifferencing, DecompositionPipeline (polynomial trend + pattern seasonality), and residuals.