Skip to content

Global model

polars_ts.global_model

Global forecasting model — one model across all series.

Implements Ch 10 of "Modern Time Series Forecasting with Python" (2nd Ed.). A global model pools data from all time series and optionally encodes series identity and static features.

GlobalForecaster

Train a single ML model across all time series in a panel.

Extends :class:ForecastPipeline with cross-series learning, optional series-identity encoding, and static exogenous features.

Parameters

estimator A scikit-learn-compatible estimator with fit and predict. lags Lag offsets for lag features. rolling_windows Window sizes for rolling aggregations. rolling_aggs Aggregation functions for rolling features. calendar Calendar features to extract. fourier Fourier term specs as [(period, n_harmonics), ...]. target_transform Optional transform: "log", "boxcox", or "difference". transform_kwargs Arguments passed to the transform function. encode_id How to encode series identity: "ordinal" maps each ID to an integer, "onehot" creates binary indicator columns. None (default) does not encode the ID. static_features Column names of static (per-series) exogenous features to include in the feature matrix (e.g. ["store_type"]). String columns are ordinal-encoded automatically. past_covariates Column names of time-varying covariates known only up to the present. Lagged features are created automatically. future_covariates Column names of time-varying covariates known into the future (e.g. holidays, promotions). Values for the forecast horizon must be supplied in future_df at predict time. past_covariate_lags Lag offsets for past covariate features. Defaults to lags. target_col Column with the target values. id_col Column identifying each time series. time_col Column with timestamps.

fit(df)

Fit a single model on pooled data from all time series.

Parameters

df Training DataFrame with id_col, time_col, target_col, and any static_features columns.

Returns

GlobalForecaster Fitted model (self).

predict(df, h, future_df=None)

Generate h-step-ahead forecasts for all series.

Parameters

df DataFrame containing history to predict from. Must include any static_features columns. h Forecast horizon. future_df DataFrame with future covariate values for the forecast horizon. Required when future_covariates were specified at construction.

Returns

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

_build_extra_features(gid)

Build the identity + static feature vector for a series.