Skip to content

MSTL Crossvalidation (refit=False) issue  #969

Description

@GGA-PERSO

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions