Forecaster#

class openstef_models.models.forecasting.forecaster.Forecaster(**data: Any) None[source]

Bases: BaseConfig, BatchPredictor[ForecastInputDataset, ForecastDataset], ABC

Base for forecasters that handle multiple horizons simultaneously.

Designed for models that train and predict across multiple prediction horizons in a unified manner. These models handle the complexity of different lead times internally, providing a simpler interface for multi-horizon forecasting.

Ideal for models that can share parameters or features across horizons, avoiding the need to train separate models for each prediction distance.

Concrete forecasters subclass this directly and declare their fields (quantiles, horizons, hyperparams, etc.) as Pydantic model fields. Mutable runtime state (e.g. the underlying ML model) should be stored in PrivateAttr fields and initialised in model_post_init.

Invariants

  • Predictions must include all quantiles specified in the configuration

  • predict_batch() only called when supports_batching returns True

Example

Creating a forecaster with multiple horizons

>>> from openstef_core.types import LeadTime, Quantile
>>> from openstef_models.models.forecasting.flatliner_forecaster import FlatlinerForecaster
>>> forecaster = FlatlinerForecaster(
...     quantiles=[Quantile(0.1), Quantile(0.5), Quantile(0.9)],
...     horizons=[LeadTime.from_string("PT1H"), LeadTime.from_string("PT6H")],
... )
>>> len(forecaster.horizons)
2
>>> str(forecaster.max_horizon)
'PT6H'

See also

XGBoostForecaster: Tree-based forecaster using XGBoost. GBLinearForecaster: Linear forecaster using XGBoost’s gblinear booster. LGBMForecaster: Tree-based forecaster using LightGBM.

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

quantiles: list[Quantile]
horizons: list[LeadTime]
supports_batching: bool
property max_horizon: LeadTime

Returns the maximum lead time (horizon) from the configured horizons.

Useful for determining the furthest prediction distance required by the model. This is commonly used for data preparation and validation logic.

Returns:

The maximum lead time.

with_horizon(horizon: LeadTime) Self[source]

Create a new configuration with a different horizon.

Parameters:
  • horizon (LeadTime) – The new lead time to use for predictions.

  • horizon

Returns:

New configuration instance with the specified horizon.

Return type:

Self

abstract property hparams: HyperParams

Model hyperparameters for training and prediction.

Concrete forecasters implement this by returning their narrowed hyperparams field, giving callers a polymorphic read-only view while each subclass keeps full type safety on its own field.