flexmeasures.data.models.forecasting.pipelines.train_predict

Classes

class flexmeasures.data.models.forecasting.pipelines.train_predict.TrainPredictPipeline(config: dict | None = None, delete_model: bool = False, save_config: bool = True, save_parameters: bool = True)
__init__(config: dict | None = None, delete_model: bool = False, save_config: bool = True, save_parameters: bool = True)

Base class for the Schedulers, Reporters and Forecasters.

The configuration config stores static parameters, parameters that, if changed, trigger the creation of a new DataSource. Dynamic parameters, such as the start date, can go into the parameters. See docstring of the method DataGenerator.compute for more details. Nevertheless, the parameter save_parameters can be set to True if some parameters need to be saved to the DB. In that case, the method _clean_parameters is called to remove any field that is not to be persisted, e.g. time parameters which are already contained in the TimedBelief.

Create a new DataGenerator with a certain configuration. There are two alternatives to define the parameters:

  1. Serialized through the keyword argument config.

  2. Deserialized, passing each parameter as keyword arguments.

The configuration is validated using the schema _config_schema, to be defined by the subclass.

config cannot contain the key config at its top level, otherwise it could conflict with the constructor keyword argument config when passing the config as deserialized attributes.

Example:

The configuration requires two parameters for the PV and consumption sensors.

Option 1:
dg = DataGenerator(config = {

“sensor_pv” : 1, “sensor_consumption” : 2

})

Option 2:

sensor_pv = Sensor.query.get(1) sensor_consumption = Sensor.query.get(2)

dg = DataGenerator(sensor_pv = sensor_pv,

sensor_consumption = sensor_consumption)

Parameters:
  • config – serialized config parameters, defaults to None

  • save_config – whether to save the config into the data source attributes

  • save_parameters – whether to save the parameters into the data source attributes

_compute_forecast(**kwargs) list[dict[str, Any]]

Overwrite with the actual computation of your forecast.

Returns list of dictionaries, for example:
[
{

“sensor”: 501, “data”: <a BeliefsDataFrame>,

},

]

_config_schema: Schema | None = <TrainPredictPipelineConfigSchema(many=False)>
run_cycle(train_start: datetime, train_end: datetime, predict_start: datetime, predict_end: datetime, counter: int, multiplier: int, **kwargs)

Runs a single training and prediction cycle.