darts icon indicating copy to clipboard operation
darts copied to clipboard

[New Model] Forecasting with Moving Average

Open cmayoracurzio opened this issue 3 years ago • 4 comments

Is your feature request related to a current problem? Please describe.

Moving Average (MA) is used as a "baseline model" in many time-series forecasting use cases. With the current darts library, we only have access to MA as:

  • a Filtering Model (issue: only applicable to past time series),
  • or as a special case of the ARIMA models (issue: quite slow, if in the end all we want to obtain is a MA).

Describe proposed solution

Implement MA as a Forecasting Model class, so all the underlying functions (fit, predict, backtesting, gridsearch, etc.) can be used. Potentially the work already done for MA Filtering Model can be leveraged.

Describe potential alternatives

  • An example or code snippet on how to use the existing MA Filtering Model for this purpose (viz. predict, not filter). This is somewhat what I expected to find in this example (https://unit8co.github.io/darts/examples/10-Kalman-filter-examples.html) upon reading its title ("Filtering and predicting using the darts filters").
  • Speed up ARIMA models drastically if a pure MA is requested.

Thanks in any case for the great library, awesome work!

cmayoracurzio avatar May 10 '22 12:05 cmayoracurzio

+1, adding to our backlog, thanks for the suggestion. Also, please let us know if you would be interesting to make a contribution around this.

hrzn avatar May 10 '22 20:05 hrzn

@hrzn my Python and GitHub chops need to improve a lot before I can confidently contribute, but if there are any non-technical improvements you might already have identified, glad to help there.

In the meantime we'll have a look at open issues in case we can shed light on some of them.

cmayoracurzio avatar May 11 '22 13:05 cmayoracurzio

Since the model is first fit and then used to predict future values, the prediction of a moving average model would always be the mean of the last window number of values in the time series used for training (with a constant value as the prediction independent of the forecast horizon). This would be equivalent to using the NaiveMean on the last window of the time series. Is this logic correct?

shaido987 avatar Jun 17 '22 06:06 shaido987

Since the model is first fit and then used to predict future values, the prediction of a moving average model would always be the mean of the last window number of values in the time series used for training (with a constant value as the prediction independent of the forecast horizon). This would be equivalent to using the NaiveMean on the last window of the time series. Is this logic correct?

Yes I think that's correct.

hrzn avatar Aug 22 '22 15:08 hrzn

@hrzn Hi, could I pick up this issue?

JanFidor avatar Feb 09 '23 21:02 JanFidor

@JanFidor yes, that'd be great! On second thoughts though I'm not quite sure this statement was correct:

Since the model is first fit and then used to predict future values, the prediction of a moving average model would always be the mean of the last window number of values in the time series used for training (with a constant value as the prediction independent of the forecast horizon). This would be equivalent to using the NaiveMean on the last window of the time series. Is this logic correct?

Rather I think for forecasting a horizon of n future points using a moving average, this would have to be done auto-regressively:

  • forecasting first the point t+1 as the average of the preceding t-w+1, ..., t time steps,
  • the second point t+2 as the average of the preceding t-w+2, ..., t+1 time steps,
  • .. etc all the way up to t + n.

where w is the window length and the model parameter.

Would this make sense? There might be something in Pandas we could reuse.

hrzn avatar Feb 10 '23 11:02 hrzn

There was an initial attempt here as well: https://github.com/unit8co/darts/pull/1201 but it required changes so we could also start over.

hrzn avatar Feb 10 '23 12:02 hrzn