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

AutoARIMA with CSS method fails if residuals are zero #958

Closed
andrewscottm opened this issue Dec 19, 2024 · 3 comments · Fixed by #960
Closed

AutoARIMA with CSS method fails if residuals are zero #958

andrewscottm opened this issue Dec 19, 2024 · 3 comments · Fixed by #960
Labels

Comments

@andrewscottm
Copy link
Contributor

What happened + What you expected to happen

AutoARIMA with the CSS method (or with the standard CSS-ML method but approximation=True) will fail if a model returning residuals all equal to zero is encountered in the search, i.e., if sigma2 = 0. The issue stems from python's math.log not supporting 0 at L787 of myarima. A fix might be to replace with

        if method == "CSS":
            if fit["sigma2"] <= 0:
                fit["aic"] = -math.inf
            else:
                fit["aic"] = offset + nstar * math.log(fit["sigma2"]) + 2 * npar

Versions / Dependencies

statsforecast 2.0.0
numpy 2.0.2
pandas 2.2.3
Python 3.11.10 (main, Oct 3 2024, 02:37:52) [Clang 14.0.6 ]
MacOS 15.2

Reproducible example

import pandas as pd
from statsforecast import StatsForecast
from statsforecast.models import AutoARIMA

df = pd.DataFrame({
    'unique_id': '0',
    'ds': pd.date_range(start='2000-01-01', periods=185, freq='1D'),
    'y': [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2.,
          2., 2., 2., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.,
          3., 3., 3.]
    })

m = StatsForecast(models=[AutoARIMA(season_length=7, method='CSS')], freq='1D', n_jobs=1)
m.fit(df=df)

results in error

  File /opt/anaconda3/envs/test/lib/python3.11/site-packages/statsforecast/arima.py:787 in myarima
    fit["aic"] = offset + nstar * math.log(fit["sigma2"]) + 2 * npar

ValueError: math domain error

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@jmoralez
Copy link
Member

Hey, thanks for the detailed report. Indeed that looks like the fix, would you like to contribute it?

@andrewscottm
Copy link
Contributor Author

Sure. I'll make the fix

@andrewscottm
Copy link
Contributor Author

please see #960

@jmoralez jmoralez linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants