Skip to content

Weighted

polars_ts.ensemble.weighted

Weighted forecast ensemble.

Combines multiple forecast DataFrames using equal, manual, or inverse-error-optimized weights.

WeightedEnsemble

Combine multiple forecasts using weighted averaging.

Accepts pre-computed forecast DataFrames and combines them. No model training is performed.

Parameters

weights Weighting strategy:

- ``"equal"`` (default): all models get equal weight ``1/n``.
- ``"inverse_error"``: weights are ``1/MAE`` normalized to sum
  to 1. Requires ``validation_pairs`` in :meth:`combine`.
- A ``list[float]``: explicit weights (will be normalized).

id_col Column identifying each time series. time_col Column with timestamps.

combine(forecasts, validation_dfs=None)

Combine forecast DataFrames into a single ensemble forecast.

Parameters

forecasts List of forecast DataFrames, each with [id_col, time_col, "y_hat"]. validation_dfs Required when weights="inverse_error". List of DataFrames (one per model), each with y and y_hat columns for computing per-model MAE.

Returns

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

_join_forecasts(forecasts, id_col, time_col)

Join multiple forecast DataFrames on (id_col, time_col).

Renames each y_hat column to y_hat_0, y_hat_1, etc. Validates that all forecasts share the same (id_col, time_col) rows.

Returns

pl.DataFrame Joined DataFrame with columns [id_col, time_col, y_hat_0, y_hat_1, ...].