flexmeasures.data.models.forecasting.pipelines.predict

Classes

class flexmeasures.data.models.forecasting.pipelines.predict.PredictPipeline(sensors: dict[str, int], regressors: list[str], future_regressors: list[str], target: str, model_path: str, output_path: str, n_hours_to_predict: int, max_forecast_horizon: int, sensor_to_save: Sensor, forecast_frequency: int = 1, probabilistic: bool = False, quantiles: list[float] | None = None, event_starts_after: datetime | None = None, event_ends_before: datetime | None = None, predict_start: datetime | None = None, predict_end: datetime | None = None)
__init__(sensors: dict[str, int], regressors: list[str], future_regressors: list[str], target: str, model_path: str, output_path: str, n_hours_to_predict: int, max_forecast_horizon: int, sensor_to_save: Sensor, forecast_frequency: int = 1, probabilistic: bool = False, quantiles: list[float] | None = None, event_starts_after: datetime | None = None, event_ends_before: datetime | None = None, predict_start: datetime | None = None, predict_end: datetime | None = None) None

Initialize the PredictPipeline.

Parameters:
  • sensors – Dictionary mapping custom regressor names to sensor IDs.

  • regressors – List of custom regressor names.

  • target – Custom target name.

  • model_path – Path to the model file.

  • output_path – Path where predictions will be saved.

  • n_hours_to_predict – Number of hours to predict into the future.

  • max_forecast_horizon – Maximum forecast horizon in hours.

  • quantiles – Optional list of quantiles to predict for probabilistic forecasts. If None, predictions are deterministic.

  • event_starts_after – Only consider events starting after this time.

  • event_ends_before – Only consider events ending before this time.

  • predict_start – Only save events starting after this time.

  • predict_end – Only save events ending before this time.

  • forecast_frequency – Create a forecast every Nth interval.

_prepare_df_single_horizon_prediction(y_pred: TimeSeries, belief_horizon, value_at_belief_horizon, time_offset, belief_timestamp)

Prepare the DataFrame for a single prediction. Make an additional column for quantiles forecast when probabilistic is True

load_model()

Load the model and its metadata from the model_path.

make_multi_horizon_predictions(model, future_covariates_list, past_covariates_list, y_list, belief_timestamps_list) DataFrame

Make multiple predictions for the given model, X, and y.

make_single_horizon_prediction(model, future_covariates, past_covariates, y, time_offset, belief_timestamp) DataFrame

Make a single prediction for the given time offset, which can represent minutes or hours based on the sensor resolution. The time offset increments the belief horizon and event time in the training data.

run(delete_model: bool = False)

Execute the prediction pipeline.

save_results_to_CSV(df_pred: DataFrame)

Save the predictions to a CSV file.