Skip to content

Pipeline

polars_ts.pipeline

End-to-end ML forecasting pipeline.

Ties feature engineering and target transforms into a single fit/predict interface. Implements Ch 8 of "Modern Time Series Forecasting with Python" (2nd Ed.).

ForecastPipeline

End-to-end ML forecasting pipeline with feature engineering and transforms.

Combines lag features, rolling aggregations, calendar features, Fourier terms, and optional target transforms into a single fit/predict workflow.

Parameters

estimator A scikit-learn-compatible estimator with fit and predict. lags Lag offsets for lag features (e.g. [1, 2, 7]). rolling_windows Window sizes for rolling aggregations (e.g. [7, 14]). rolling_aggs Aggregation functions for rolling features (default ["mean"]). calendar Calendar features to extract (e.g. ["day_of_week", "month"]). fourier Fourier term specs as [(period, n_harmonics), ...]. target_transform Optional transform: "log", "boxcox", or "difference". transform_kwargs Arguments passed to the transform function (e.g. {"lam": 0.5}). target_col Column with the target values. id_col Column identifying each time series. time_col Column with timestamps.

fit(df)

Fit the pipeline: transform target, build features, train model.

Parameters

df Training DataFrame with id_col, time_col, and target_col.

Returns

ForecastPipeline Fitted pipeline (self).

predict(df, h)

Generate h-step-ahead forecasts using recursive prediction.

Parameters

df DataFrame containing history to predict from. h Forecast horizon.

Returns

pl.DataFrame DataFrame with columns [id_col, time_col, "y_hat"].

_inverse_single(pred, orig_values)

Inverse-transform a single prediction to original scale.

_build_feature_df(df, lags, rolling_windows, rolling_aggs, calendar, fourier, target_col, id_col, time_col)

Apply all configured feature engineering steps to df.

_apply_transform(df, transform, kwargs, target_col, id_col, time_col)

Apply a target transform and return (transformed_df, state).

_build_step_features(buffer, timestamp, lags, rolling_windows, rolling_aggs, calendar, fourier_specs, step_index, _time_col)

Build a single feature vector for one recursive prediction step.