uber / orbit

A Python package for Bayesian forecasting with object-oriented design and probabilistic models under the hood.
https://orbit-ml.readthedocs.io/en/stable/
Other
1.87k stars 134 forks source link

"IndexError: list index out of range" when trying to fit KTR model #770

Closed allomulder closed 2 years ago

allomulder commented 2 years ago

Describe the bug When I try to fit KTR model and specify any kind of seasonality, it throws an "IndexError: list index out of range" error. Interestingly, when I manually specify seasonality_fs_order, it fits normally, but if I try to refit the same model it still throws the same error. This also breaks the Backtester.

To Reproduce Run the example from first tutorial on KTR. Running the ktr_with_seas.fit(train_df) cell twice gets this error.

Expected behavior Model should fit and refit normally.

Screenshots image

Environment:

wangzhishi commented 2 years ago

when you said any kind of seasonality, which one did you use?

allomulder commented 2 years ago

I found this bug on subdaily data (hourly resolution), with seasonality length = 24. However, the same problem appears when I try to run the complex seasonality example from tutorial:

ktr_with_seas = KTR(
    response_col=response_col,
    date_col=date_col,
    seed=2021,
    seasonality=[7, 365.25],
    estimator='pyro-svi',
    n_bootstrap_draws=1e4,
    # pyro training config
    num_steps=301,
    message=100,
)

ktr_with_seas.fit(train_df)

When I run that block of code once, it works without any problems. However, if I try to run ktr_with_seas.fit(train_df) again without re-instantiation of the model, it throws an error above.

Also I mistyped above - in that environment python version is 3.8.13, not 3.9.13.

wangzhishi commented 2 years ago

This IndexError is caused by a mis-placement of certain internal attributes related to seasonality. It is fixed in the PR #771. Let me know if it also addresses the problem with your sub-daily hourly data.

You may have to install the dev branch to fix this error.

allomulder commented 2 years ago

@wangzhishi sorry for a big lag, only now got my hands on it. Now it works correctly and without any noticable bugs, thank you!

Maybe consider adding that to a main release, like 1.1.3? It is a breaking bug, after all.