pretab.transformers.LagFeatureTransformer

class pretab.transformers.LagFeatureTransformer(n_lags=1)[source]

Bases: BasePreTabTransformer

Create 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_lags observations have no complete history, the transformed output has n_samples - n_lags rows. Each input feature is expanded into n_lags lagged 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 therefore Preprocessor) 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