Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Model] Forecasting with Moving Average #951

Closed
cmayoracurzio opened this issue May 10, 2022 · 7 comments · Fixed by #1557
Closed

[New Model] Forecasting with Moving Average #951

cmayoracurzio opened this issue May 10, 2022 · 7 comments · Fixed by #1557
Labels
good first issue Good for newcomers new model Adding a new model

Comments

@cmayoracurzio
Copy link

cmayoracurzio commented May 10, 2022

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 cmayoracurzio added the triage Issue waiting for triaging label May 10, 2022
@hrzn hrzn added new model Adding a new model and removed triage Issue waiting for triaging labels May 10, 2022
@hrzn
Copy link
Contributor

hrzn commented May 10, 2022

+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.

@cmayoracurzio
Copy link
Author

@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.

@shaido987
Copy link
Contributor

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?

@hrzn hrzn added the good first issue Good for newcomers label Aug 22, 2022
@hrzn
Copy link
Contributor

hrzn commented Aug 22, 2022

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.

@JanFidor
Copy link
Contributor

JanFidor commented Feb 9, 2023

@hrzn Hi, could I pick up this issue?

@hrzn
Copy link
Contributor

hrzn commented Feb 10, 2023

@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
Copy link
Contributor

hrzn commented Feb 10, 2023

There was an initial attempt here as well: #1201 but it required changes so we could also start over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new model Adding a new model
Projects
None yet
4 participants