Fix/969 MSTL cross validation with refit = False#1100
Conversation
…indows in cv with insufficient training data
…insufficient data
…s (values are numpy.ndarray's), add instruction regarding how to run the m3 test locally CI-style
|
I reviewed the CI/CD jobs that failed, all are with |
|
I noticed that statsforecast was updated, I will incorporate the latests changes, and update the PR so that it integrates smoothly |
…ufficient data by default
…ty for short windows
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Hi, I reviewed how other models handle windows with insufficient data; MSTL's new |
|
From a supply chain planning perspective, forecast accuracy should be evaluated not only using statistical error metrics but also based on downstream operational impact. For example:
It may be valuable to introduce business-oriented evaluation metrics that complement traditional statistical measures, enabling better alignment between forecasting models and real-world supply chain performance. I would be happy to propose a structured framework for integrating such metrics into the evaluation pipeline. |
|
Adding a quick extension to this idea: In supply chain applications, evaluation metrics could be extended to include:
This could help bridge the gap between model accuracy and operational decision quality. Happy to collaborate on defining such evaluation extensions if useful. |
Hello Nixtla, I propose a solution to an issue that was first reported in #969
The problem is that cross validation with MSTL fails when the training windows are shorter than
season_lenght; I added a new parametershort_train_behaviorthat defines the behaviour when training window is shorter than maxseason_length, to either returnNaNforecasts (default) or to skip the window, this only apply during cross-validation.In addition, I added a note to the MSTL model page, and updated the MSTL class documentation string, so it is reflected in the API reference.
Feasibility over filling early windows
Using only CV windows with sufficient data aligns with the best practice: it is better to have "less but real" data than "more but fake" data for statistical validity; filling early validation windows is considered a high-risk practice because it can lead to overfitting and model failure in production.
The core goal of cross-validation is to estimate the model’s generalization error, when filling data synthetically, we are no longer measuring how the model performs on the real-world process; we are measuring how well it can "learn" the specific generator used to create the synthetic data(e.g. recycling values to complete train window).
Why
Reproducing the example provided, MSTL with
cross_validation(..., refit=False)raises:This occurs when early CV windows have fewer training observations than
season_length:h=12,n_windows=3,step_size=1→ test_size=14_predict_mstl_seasto fail innp.tile()The bug is MSTL-specific: I verified that Naive, SeasonalNaive, AutoETS, Holt, AutoARIMA, and DynamicOptimizedTheta all succeed with the same CV settings; other models either handle short series differently or avoid this case.
Solution
I reviewed how other StatsForecasts models handle windows with insufficient data; MSTL's new
short_train_behaviorparameter handles this: usingnanreturns NaN predictions (default, such as in SN/SES/SWA), while withskiponly windows with sufficient training data are evaluated and returned; this only applies during cross-validation with MSTL so regular forecasts aren’t altered by short training windows.Impact
short_train_behaviorapplies only when a model defines it (currently MSTL), for others no windows are skipped; in addition, this only applies in cross-validation, there is no change to non-CV forecasting behavior for MSTL.Changes
python/statsforecast/core.py: temporarily toggles a CV-only flag (_cv_short_train_behavior) around cross-validation and restores it afterward.python/statsforecast/models.py: guards short-train handling andmin_train_sizebehind the CV-only flag; docstring clarifies CV-only scope.tests/test_mstl.py: updates forecast expectations to confirm short_train_behavior is ignored outside CV.nbs/docs/models/MultipleSeasonalTrend.ipynb /nbs/docs/tutorials/MultipleSeasonalities.ipynb: documentation notes CV-specific behavior.Closes #969 issue.