tabularize¶
yohou.utils.tabularize(df_time_series, lags)
¶
Convert time series to tabular format using lags.
Creates a tabular dataset by generating lagged versions of each time series column. This is the core operation for reduction-based forecasting, enabling use of sklearn estimators for time series prediction.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
df_time_series
|
DataFrame
|
Time series DataFrame with columns to be lagged. Columns with
|
required |
lags
|
Sequence of int
|
Lag values to create. Each value i creates features shifted by i time steps. For example, lags=[1, 2, 3] creates lag_1, lag_2, and lag_3 features. |
required |
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Tabularized DataFrame with lagged feature columns. The first max(lags) rows are dropped since they would contain null values. Column names follow the pattern "{original_column}lag". |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> # Original time series with a contract-compliant datetime "time" column
>>> df = pl.DataFrame({
... "time": pl.datetime_range(datetime(2020, 1, 1), datetime(2020, 1, 5), "1d", eager=True),
... "value": [10, 20, 30, 40, 50],
... })
>>> # Create lag features for lags 1, 2
>>> df_tabular = tabularize(df, lags=[1, 2])
>>> df_tabular
shape: (3, 3)
┌─────────────────────┬─────────────┬─────────────┐
│ time ┆ value_lag_1 ┆ value_lag_2 │
│ --- ┆ --- ┆ --- │
│ datetime[μs] ┆ i64 ┆ i64 │
╞═════════════════════╪═════════════╪═════════════╡
│ 2020-01-03 00:00:00 ┆ 20 ┆ 10 │
│ 2020-01-04 00:00:00 ┆ 30 ┆ 20 │
│ 2020-01-05 00:00:00 ┆ 40 ┆ 30 │
└─────────────────────┴─────────────┴─────────────┘
See Also ¶
BaseReductionForecaster: Uses tabularize for forecastingLagTransformer: Transformer that applies similar lagging logic