BaseCaseForecaster#
- class openstef_models.models.forecasting.base_case_forecaster.BaseCaseForecaster(**data: Any) None[source]
Bases:
Forecaster,ExplainableForecaster,ContributionsMixinBase case forecaster that repeats weekly patterns for predictions.
A simple baseline forecasting model that uses pandas-native operations to repeat the last week of historical target data for forecasting. This model serves as a naive baseline for comparison with more sophisticated forecasting approaches, implementing the common assumption that energy load patterns exhibit weekly periodicity.
The forecaster takes the last week of historical data (based on primary_lag, default: 7 days) and uses pandas reindex with forward fill to repeat this weekly pattern until the end of the forecast period. Missing values are filled using the fallback lag period (default: 14 days, representing 2 weeks ago).
The confidence intervals are calculated using hourly standard deviations computed from the repeated base case data, providing uncertainty estimates for each prediction.
Example
>>> from openstef_core.types import LeadTime, Quantile >>> from datetime import timedelta >>> >>> # Default configuration (7-day primary, 14-day fallback) >>> forecaster = BaseCaseForecaster( ... quantiles=[Quantile(0.1)], ... horizons=[LeadTime(timedelta(hours=1))], ... ) >>> >>> # Custom lag configuration >>> custom_forecaster = BaseCaseForecaster( ... quantiles=[Quantile(0.5)], ... horizons=[LeadTime(timedelta(hours=1))], ... hyperparams=BaseCaseForecasterHyperParams( ... primary_lag=timedelta(days=7), ... fallback_lag=timedelta(days=21), ... ), ... ) >>> >>> # Works directly with target variable in the dataset >>> forecaster.fit(training_data) >>> predictions = forecaster.predict(forecast_data)
Note
The forecaster works directly with the target variable in the input dataset, automatically detecting the forecast period from the forecast_start parameter and repeating the appropriate historical weekly pattern.
- Parameters:
data (
Any)
-
hyperparams:
BaseCaseForecasterHyperParams
- property hparams: BaseCaseForecasterHyperParams
Model hyperparameters for training and prediction.
Concrete forecasters implement this by returning their narrowed
hyperparamsfield, giving callers a polymorphic read-only view while each subclass keeps full type safety on its own field.
- property is_fitted: bool
Check if the predictor has been 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:
data (
ForecastInputDataset) – The training data to fit the predictor on.data_val (
ForecastInputDataset|None) – The validation data to evaluate and tune the predictor on (optional).data
data_val
- Return type:
- predict(data: ForecastInputDataset) ForecastDataset[source]
Generate predictions using repeated weekly patterns with confidence intervals.
- Parameters:
data (
ForecastInputDataset) – The forecast input dataset containing target variable history.data
- Returns:
ForecastDataset containing quantile predictions for the forecast period.
- Return type:
- predict_contributions(data: ForecastInputDataset) TimeSeriesDataset[source]
Return uniform contributions.
- Parameters:
data (
ForecastInputDataset)- Return type:
- 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.
- 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].