flexmeasures.data.models.forecasting.pipelines.train

Classes

class flexmeasures.data.models.forecasting.pipelines.train.TrainPipeline(sensors: dict[str, int], regressors: list[str], future_regressors: list[str], target: str, model_save_dir: str, n_hours_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)
__init__(sensors: dict[str, int], regressors: list[str], future_regressors: list[str], target: str, model_save_dir: str, n_hours_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) None

Initialize the TrainPipeline.

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

  • regressors – List of custom regressor names.

  • target – Custom target name.

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

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

  • max_forecast_horizon – Maximum forecast horizon in hours.

  • event_starts_after – Only consider events starting after this time.

  • event_ends_before – Only consider events ending before this time.

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.