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

[BUG] convert to period bug in _StatsModelsAdapter #5641

Closed
ciaran-g opened this issue Dec 19, 2023 · 1 comment · Fixed by #5642
Closed

[BUG] convert to period bug in _StatsModelsAdapter #5641

ciaran-g opened this issue Dec 19, 2023 · 1 comment · Fixed by #5642
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Comments

@ciaran-g
Copy link
Contributor

Describe the bug

For panel data with datetime indexes, converting datetimes to period index causes an error in the predict stage in the _StatsModelsAdapter models

To Reproduce

from sktime.datasets import load_airline
from sktime.forecasting.exp_smoothing import ExponentialSmoothing
import pandas as pd
y = load_airline()

# create dummy index with hourly timestamps and panel data by hour of day
y.index = pd.date_range(start='1960-01-01', periods=len(y.index), freq='H')
y.index.names = ["datetime"]
y.name = "passengers"
y = y.to_frame()
y['hour_of_day'] = y.index.hour
y = y.reset_index().set_index(['hour_of_day', 'datetime']).sort_index()

forecaster = ExponentialSmoothing(
    trend='add', sp=1
)  
forecaster.fit(y)
forecaster.predict(fh=[1])

Expected behavior

For each panel predict one step ahead

Additional context

I will address this issue 👍

Versions

Python dependencies:
pip: 23.1.2
sktime: 0.24.1
sklearn: 1.2.2
skbase: 0.6.1
numpy: 1.24.3
scipy: 1.10.1
pandas: 2.0.2
matplotlib: None
joblib: 1.2.0
numba: None
statsmodels: 0.14.0
pmdarima: 2.0.3
statsforecast: None
tsfresh: None
tslearn: None
torch: None
tensorflow: None
tensorflow_probability: None

@ciaran-g ciaran-g added the bug Something isn't working label Dec 19, 2023
@fkiraly fkiraly added the module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting label Dec 19, 2023
@fkiraly
Copy link
Collaborator

fkiraly commented Dec 19, 2023

We should add a test for all forecasters - that could be done in utils._testing.scenarios_forecasting, in forecasting_scenarios_extended

fkiraly pushed a commit that referenced this issue Dec 24, 2023
…5642)

Fixes #5641 


#### What does this implement/fix? Explain your changes.
<!--
A clear and concise description of what you have implemented.
-->

Rather than convert to period just use the integer positions in
`_StatsModelsAdapter`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants