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

MSTL Crossvalidation (refit=False) issue #969

Open
GGA-PERSO opened this issue Jan 16, 2025 · 1 comment
Open

MSTL Crossvalidation (refit=False) issue #969

GGA-PERSO opened this issue Jan 16, 2025 · 1 comment
Labels

Comments

@GGA-PERSO
Copy link

What happened + What you expected to happen

I raise following exception with cross validation and MSTL Model (MSTL(season_length = [12],alias='MSTL'))

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\statsforecast\models.py:5273, in MSTL.forward(self, y, h, X, X_future, level, fitted)
   5269         res = self.trend_forecaster._add_conformal_intervals(
   5270             fcst=res, y=x_sa, X=X, level=level
   5271         )
   5272 # reseasonalize results
-> 5273 seas_h = _predict_mstl_seas(model_, h=h, season_length=self.season_length)
   5274 seas_insample = model_.filter(regex="seasonal*").sum(axis=1).values
   5275 res = {
   5276     key: val + (seas_insample if "fitted" in key else seas_h)
   5277     for key, val in res.items()
   5278 }

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\statsforecast\models.py:4999, in _predict_mstl_seas(mstl_ob, h, season_length)
   4998 def _predict_mstl_seas(mstl_ob, h, season_length):
-> 4999     seascomp = _predict_mstl_components(mstl_ob, h, season_length)
   5000     return seascomp.sum(axis=1)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\statsforecast\models.py:4992, in _predict_mstl_components(mstl_ob, h, season_length)
   4990     mp = seasonal_periods[i]
   4991     colname = seasoncolumns[i]
-> 4992     seascomp[:, i] = np.tile(
   4993         mstl_ob[colname].values[-mp:], trunc(1 + (h - 1) / mp)
   4994     )[:h]
   4995 return seascomp

ValueError: could not broadcast input array from shape (10,) into shape (12,)

TIME SERIE LENGTH = 25Months
TEST SIZE CV = window_size_for_cv + step_size_for_cv * (nb_windows_for_cv - 1) = 14

What let me think that there is an issue is if you reduce the number of month of data to 15 then it works. If it doesn't work for 25Months I don't understand why it could work with less data with the same CV configuration

Versions / Dependencies

StatsForecast 2.0.0

Reproducible example

  
import pandas as pd
from statsforecast import StatsForecast
from statsforecast.models import (Naive,MSTL) 
from utilsforecast.data import generate_series

freq = 'MS'
season_length = 12
min_length = 25

df = generate_series(n_series=1, freq=freq, min_length=min_length, max_length=min_length)

sffcst = StatsForecast(models = [MSTL(season_length = [season_length])], freq = freq, n_jobs=-1,fallback_model=Naive(),verbose=True)
sf_crossvalidation_df=sffcst.cross_validation(df = df, h=12, step_size = 1, n_windows = 3, refit=False).reset_index(drop=True)
sf_crossvalidation_df

Issue Severity

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

@GGA-PERSO GGA-PERSO added the bug label Jan 16, 2025
@GGA-PERSO GGA-PERSO changed the title MSTL Crossvalidation issue MSTL Crossvalidation (refit=False) issue Jan 16, 2025
@GGA-PERSO
Copy link
Author

probably linked to the refit=False but i don't understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant