Skip to content

Conversation

KaiAllAlone
Copy link

Describe your change:

Added the ARIMA Algorithm.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 11, 2025
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.



class ARIMA:
def __init__(self, p=1, d=1, q=1, lr=0.001, epochs=1000) -> None:

Choose a reason for hiding this comment

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

Please provide type hint for the parameter: p

Please provide descriptive name for the parameter: p

Please provide type hint for the parameter: d

Please provide descriptive name for the parameter: d

Please provide type hint for the parameter: q

Please provide descriptive name for the parameter: q

Please provide type hint for the parameter: lr

Please provide type hint for the parameter: epochs

self.n_train: int | None = None
self.sigma_err: float | None = None

def difference(self, data) -> NDArray[np.float64]:

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function difference

Please provide type hint for the parameter: data

diff = np.diff(diff) # np.diff is a handy function that does exactly this.
return diff

def inverse_difference(

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function inverse_difference

prev = next_val
return forecast

def _compute_residuals(

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function _compute_residuals

diff_data: NDArray[np.float64],
phi: NDArray[np.float64],
theta: NDArray[np.float64],
c: float,

Choose a reason for hiding this comment

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

Please provide descriptive name for the parameter: c


return preds, errors

def fit(self, data: list[float] | NDArray[np.float64]) -> "ARIMA":

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function fit

self.n_train = len(diff_data) # Assign n_train as an integer
return self

def _fit_gradient_descent(self, diff_data: NDArray[np.float64], start: int) -> None:

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function _fit_gradient_descent

msg = f"Fitted params (GD): phi={self.phi},theta={self.theta},c={self.c:.6f}\n"
print(msg)

def forecast(

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file machine_learning/arima.py, please provide doctest for the function forecast

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 11, 2025
@KaiAllAlone KaiAllAlone changed the title Added arima Added ARIMA Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html

1 participant