Skip to content

fix: compute the seasonal ETS interval variance per step - #1243

Open
Max Gorbuk (mkzung) wants to merge 1 commit into
Nixtla:mainfrom
mkzung:fix/ets-seasonal-interval-per-step
Open

Max Gorbuk (mkzung) wants to merge 1 commit into
Nixtla:mainfrom
mkzung:fix/ets-seasonal-interval-per-step

Conversation

@mkzung

Copy link
Copy Markdown

_compute_pred_intervals computes the seasonal count once, from the whole horizon:

steps = steps = np.arange(1, h + 1)
hm = np.floor((h - 1) / season_length)

hm then sits next to steps in the ANA, AAA and AAdA variances, so every step gets the count of the last one. In Hyndman, Koehler, Ord and Snyder (2008), ch. 6, it is the count for the step being forecast. The visible effect is that the step-1 interval depends on how far ahead you forecast:

from statsforecast.models import AutoETS
from statsforecast.utils import AirPassengers as ap

m = AutoETS(season_length=12, model="ANA").fit(ap.astype(float))
for h in (1, 36):
    p = m.predict(h=h, level=[95])
    print(h, p["hi-95"][0] - p["lo-95"][0])

On main:

1 62.02033057382857
36 103.207115866462

With this change both lines read 62.02033057382857.

The fix computes hm from steps. The added test runs all six additive-error models through _compute_pred_intervals and checks the variance against sigma2 * (1 + sum of c_j**2), with c_j = alpha + beta * (phi + ... + phi**j) + gamma * [j % m == 0]. The three non-seasonal models already matched; the three seasonal ones fail on main and pass here. tests/test_ets.py is 84 passed and tests/test_models.py 206 passed.

_compute_pred_intervals took hm = floor((h - 1) / m) from the total horizon,
so ANA, AAA and AAdA used the last step's seasonal count at every step and the
step-1 interval widened as the horizon grew. hm is now computed for each step,
which is how the class 1 formulas in Hyndman et al. (2008), ch. 6 define it.

The new test checks all six additive-error models against the c_j recursion.
@CLAassistant

CLAassistant commented Sep 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants