flexmeasures.data.models.forecasting.pipelines.train

Classes

class flexmeasures.data.models.forecasting.pipelines.train.TrainPipeline(future_regressors: list[Sensor], past_regressors: list[Sensor], target_sensor: Sensor, model_save_dir: str, n_steps_to_predict: int, max_forecast_horizon: int, forecast_frequency: int = 1, event_starts_after: datetime | None = None, event_ends_before: datetime | None = None, probabilistic: bool = False, ensure_positive: bool = False, missing_threshold: float = 1.0)
__init__(future_regressors: list[Sensor], past_regressors: list[Sensor], target_sensor: Sensor, model_save_dir: str, n_steps_to_predict: int, max_forecast_horizon: int, forecast_frequency: int = 1, event_starts_after: datetime | None = None, event_ends_before: datetime | None = None, probabilistic: bool = False, ensure_positive: bool = False, missing_threshold: float = 1.0) None

Initialize the TrainPipeline.

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

  • past_regressors – List of sensors serving as past regressors.

  • future_regressors – List of sensors serving as future regressors.

  • target – Custom target name.

  • model_save_dir – Directory where the trained model will be saved.

  • n_steps_to_predict – Number of steps of 1 resolution to predict into the future.

  • max_forecast_horizon – Maximum forecast horizon in steps of 1 resolution.

  • event_starts_after – Only consider events starting after this time.

  • event_ends_before – Only consider events ending before this time.

  • forecast_frequency – Frequency of the forecast in hours.

  • probabilistic – Whether to use a probabilistic model.

  • ensure_positive – Whether to ensure that predictions are positive.

  • missing_threshold – Max fraction of missing data allowed before failure. Missing data under the threshold will be filled with our interpolation methods.

run(counter: int)

Runs the training pipeline.

This function loads the data, splits it into training and testing sets, trains multiple models on the training set, and saves the trained models.

save_model(model, model_name: str)

Save the trained model to the model_save_path.

train_model(model, future_covariates: TimeSeries, past_covariates: TimeSeries, y_train: TimeSeries)

Trains the specified model using the provided training data.