pretab.transformers.LagFeatureTransformer
- class pretab.transformers.LagFeatureTransformer(n_lags=1)[source]
Bases:
BasePreTabTransformerCreate lagged features for time-series inputs.
For each input column, previous time steps are appended as additional features, which is useful for autoregressive modeling.
- Parameters:
n_lags (int, default=1) – Number of lag steps to include.
Notes
Because the first
n_lagsobservations have no complete history, the transformed output hasn_samples - n_lagsrows. Each input feature is expanded inton_lagslagged columns.This is a standalone time-series utility. It intentionally changes the row count and assumes the rows are ordered in time, so it does not satisfy the row-count-preserving contract that
ColumnTransformer(and thereforePreprocessor) require. Apply it directly to an ordered array rather than routing it through the preprocessing pipeline.Examples
>>> import numpy as np >>> from pretab.transformers import LagFeatureTransformer >>> X = np.arange(6).reshape(-1, 1) >>> transformer = LagFeatureTransformer(n_lags=2) >>> transformer.fit_transform(X).shape (4, 2)- __init__(n_lags=1)[source]
Methods
__init__([n_lags])fit(X[, y])fit_transform(X[, y])Fit to data, then transform it.
get_feature_names_out([input_features])Return output feature names of the form
{feature}_{suffix}{j}.get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
transform(X)Attributes
total_output_dim_Total number of output columns produced across all input features.
n_features_in_adaptive