etna icon indicating copy to clipboard operation
etna copied to clipboard

Enabling passing context into `Model.forecast`

Open Mr-Geekman opened this issue 1 year ago • 0 comments

🚀 Feature Request

We decided that we want to enable passing context into forecast method of the model. It will be done with a new parameter: prediction_size. First n - prediction_size points in a given ts won't be forecasted and if model needs a context, it will use this points for this.

Proposal

  1. Add prediction_size parameter for the adapters.
    • implement separately common logic on selection of last prediction_size elements of prediction
  2. Add prediction_size parameter to forecast method in classes:
    • base.Model
    • base.ForecastAbstractModel
    • base.PredictIntervalAbstractModel
    • base.PerSegmentModel -- determine the context needed for prediction and pass it into the adapter in df_context parameter, if context isn't needed don't pass df_context.
    • base.PerSegmentPredictionIntervalModel -- same as above
    • base.MultiSegmentModel -- same as above
    • base.DeepBaseAbstractModel -- rename horizon to prediction_size
    • base.DeepBaseModel -- rename horizon to prediction_size
    • add to other classes if it wasn't enough
    • default value should be None and in the body of the function correct value is determined as a maximum possible prediction_size
    • if a too big prediction_size is set (not enough context) throw an error
  3. Fix forecast in pipelines to work with context
    • Fix Pipeline.forecast, the code should be similar to snippet with DeepBaseModel
    • Fix AutoRegressivePipeline.forecast
    • Fix ensembles.

Test cases

  1. Make sure current tests pass.
  2. Test function on selection of last prediction_size elements for adapters.
  3. Test that if prediction_size is None then value is determined as len(df) - context_size. Probably, it is convenient to do with some dummy/mock model.
  4. Test that models throw error if prediction_size is too big. Look above about dummy/mock.
  5. Test that Pipeline.forecast passes big enough dataset according to `horizon. Look above about dummy/mock.
  6. Test that AutoRegressivePipeline.forecast passes big enough dataset according to horizon. Look above about dummy/mock.

Additional context

  • Is blocked by #844.
  • Merge it into an inference branch.

Mr-Geekman avatar Aug 10 '22 12:08 Mr-Geekman