Skip to content

[ENH] Add Basic ARIMA model #2860

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

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open

[ENH] Add Basic ARIMA model #2860

wants to merge 59 commits into from

Conversation

alexbanwell1
Copy link
Contributor

@alexbanwell1 alexbanwell1 commented May 28, 2025

Reference Issues/PRs

Split out of #2828
Basis for #2838

What does this implement/fix? Explain your changes.

Adds basic ARIMA forecaster, which fits phi, theta (and optionally c) parameters, but takes in the model to use e.g. ARIMA(p,d,q) and an option to include a constant term.

I have restructured this for numba purposes. The parameters were found using a bespoke implementation of Nelder Mead, sensibly generalised for any loss function. However, doing this means it cannot be cached, which massively slows it down. I have moved Nelder Mead back into the forecasting module, and have introduced an integer switch dispatch function to facilitate caching.

This currently means some duplication of code in the loss_function and in ARIMA. This is usually the price for writing numba.

  1. fit(y) sets the parameters for AR and MA component stores the one ahead forecast in self.forecast_
  2. predict(y) applies the model to assumed unseen data, setting the MA component to zero as is standard (but a bit wierd). It returns the one ahead forecast for y.
  3. forecast(y) fits on y and returns the one ahead forecast, using the residuals on y but not changing any parameter
  4. iterative_forecast(y, prediction_horizon=12) fits on y, sets the residuals as to zero after tail of y exceeded.
from aeon.datasets import load_airplane
from aeon.forecasting import ARIMA
y = load_forecasting()
a = ARIMA(p=2, d=1, q=2)
a.fit(y)
p1 = a.forecast_
p2 = a.forecast(y)
preds = a.iterative_forecast(y, prediction_horizon=12)

@aeon-actions-bot aeon-actions-bot bot added enhancement New feature, improvement request or other non-bug code enhancement forecasting Forecasting package labels May 28, 2025
@aeon-actions-bot
Copy link
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ $\color{#FEF1BE}{\textsf{enhancement}}$ ].
I have added the following labels to this PR based on the changes made: [ $\color{#31FCCD}{\textsf{forecasting}}$ ]. Feel free to change these if they do not properly represent the PR.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, any trivial fixes will automatically be pushed to your PR unless it is a draft.

Don't hesitate to ask questions on the aeon Slack channel if you have any.

PR CI actions

These checkboxes will add labels to enable/disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Stop automatic pre-commit fixes (always disabled for drafts)
  • Disable numba cache loading
  • Push an empty commit to re-run CI checks

@alexbanwell1 alexbanwell1 mentioned this pull request May 28, 2025
5 tasks
Copy link
Contributor

@TonyBagnall TonyBagnall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good start, some tidying up needed and we should think about utils structure

@alexbanwell1 alexbanwell1 requested a review from TonyBagnall June 2, 2025 19:31
@TonyBagnall
Copy link
Contributor

I have optimised the code for numba, and it is now blazingly fast at fitting.
image

and longer series

image

these results are from randomly generated stationary AR models with p 0 to 3 and q 0 to 3. For each size of n, repeat m times:
randomly generate a series, fit arma model, predict one ahead.

m set to 30 for these. I also need to do the same for iterative forecast, but these almost look too good to be true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, improvement request or other non-bug code enhancement forecasting Forecasting package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants