FlatlinerForecaster#

class openstef_models.models.forecasting.flatliner_forecaster.FlatlinerForecaster(*, quantiles: list[~openstef_core.types.Quantile] = [0.5], horizons: list[~openstef_core.types.LeadTime], supports_batching: bool = False, predict_median: bool = False, median_window: ~datetime.timedelta | None = None, hyperparams: ~openstef_core.mixins.predictor.HyperParams = <factory>)[source]

Bases: Forecaster, ExplainableForecaster, ContributionsMixin

Flatliner forecaster that predicts a flatline of zeros or median.

A simple forecasting model that always predicts zero (or a median load value if configured) for all horizons and quantiles. The median can be calculated over a trailing window when the fallback is responding to a recent flatline.

Invariants

  • Configuration quantiles determine the number of prediction outputs

  • Zeros (or median values) are predicted for all horizons and quantiles

Example

>>> from openstef_core.types import LeadTime, Quantile
>>> from datetime import timedelta
>>> forecaster = FlatlinerForecaster(
...     quantiles=[Quantile(0.5), Quantile(0.1), Quantile(0.9)],
...     horizons=[LeadTime(timedelta(hours=1)), LeadTime(timedelta(hours=2))],
... )
>>> forecaster.fit(training_data)
>>> predictions = forecaster.predict(test_data)

See also

Forecaster: Base class for forecasting models that predict multiple horizons.

Parameters:
predict_median: bool
median_window: timedelta | None
hyperparams: HyperParams
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.

Overrides:

Forecaster.hparams

property is_fitted: bool

Check if the predictor has been fitted.

Overrides:

Predictor.is_fitted

fit(data: ForecastInputDataset, data_val: ForecastInputDataset | None = None) → None[source]

Fit the predictor to the input data.

This method should be called before generating predictions. It allows the predictor to learn parameters from the training data.

Parameters:
Return type:

None

Overrides:

Predictor.fit

predict(data: ForecastInputDataset) → ForecastDataset[source]

Generate predictions for the input data.

This method should use the fitted parameters to generate predictions.

Parameters:

data (ForecastInputDataset) – The input data to generate predictions for.

Return type:

ForecastDataset

Returns:

Predictions for the input data.

Raises:

NotFittedError – If the predictor has not been fitted yet.

Overrides:

Predictor.predict

property feature_importances: DataFrame

Get feature importance scores for this model.

Returns DataFrame with feature names as index and quantiles as columns. Each quantile represents the importance distribution across multiple model training runs or folds.

Returns:

DataFrame with feature names as index and quantile columns. Values represent normalized importance scores summing to 1.0.

Note

The returned DataFrame must have feature names as index and quantile columns in format ‘quantile_PXX’ (e.g., ‘quantile_P50’, ‘quantile_P95’). All quantile values must be between 0 and 1.

Overrides:

ExplainableForecaster.feature_importances

predict_contributions(data: ForecastInputDataset) → TimeSeriesDataset[source]

Return zero contributions since flatliner has no features.

Parameters:

data (ForecastInputDataset)

Return type:

TimeSeriesDataset

Overrides:

ContributionsMixin.predict_contributions

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].

model_post_init(context: Any, /) → None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None