feat: add forward() method to AutoMFLES and AutoTBATS#1094
feat: add forward() method to AutoMFLES and AutoTBATS#1094W057 wants to merge 2 commits intoNixtla:mainfrom
Conversation
Enables cross_validation(refit=False) and integer refit for these models. The forward() method delegates to forecast() which re-fits the model on the new time series, matching the expected signature and behavior. Closes Nixtla#911
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72108f65ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
python/statsforecast/models.py
Outdated
| """ | ||
| if not hasattr(self, "model_"): | ||
| raise Exception("You have to use the `fit` method first") | ||
| return self.forecast(y=y, h=h, X=X, X_future=X_future, level=level, fitted=fitted) |
There was a problem hiding this comment.
Reuse fitted model in AutoMFLES.forward
forward currently returns self.forecast(...), but forecast calls self._fit(...) internally, so every forward invocation re-runs AutoMFLES selection instead of applying the model fitted in fit(). In cross_validation with refit=False or integer refit (documented in core.py as fit-once/periodic-refit behavior), this effectively keeps refitting on every window and can even double-fit on windows where should_fit is true, causing unexpected runtime and semantics.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
this is an important issue
python/statsforecast/models.py
Outdated
| """ | ||
| if not hasattr(self, "model_"): | ||
| raise Exception("You have to use the `fit` method first") | ||
| return self.forecast(y=y, h=h, X=X, X_future=X_future, level=level, fitted=fitted) |
There was a problem hiding this comment.
Reuse fitted model in AutoTBATS.forward
forward delegates to self.forecast(...), and forecast rebuilds the model via tbats_selection(...) each call, so the fitted self.model_ is never used for forward updates. This breaks the intended cross_validation(refit=False/int) behavior by refitting every window anyway (and doing an extra fit on scheduled refit windows), which can significantly increase compute and makes refit frequency ineffective.
Useful? React with 👍 / 👎.
…BATS AutoMFLES: store optim_params and seasonal_period from optimize(), reuse them in forward() via _MFLES.fit() directly. AutoTBATS: use model_["description"] to fix structural choices (boxcox, trend, damping, arma) so tbats_selection() only fits one combination instead of searching all. Closes Nixtla#911
Summary
forward()method toAutoMFLESandAutoTBATS, enablingcross_validation(refit=False)and integer refit valuesforecast()which re-fits the model on the new time seriesChanges
python/statsforecast/models.pyAutoMFLES.forward()afterforecast()AutoTBATS.forward()afterforecast()Test plan
AutoMFLESwithcross_validation(refit=False)works (multi-series, 3 series x 2 windows x h=12 = 72 rows)AutoMFLESwithcross_validation(refit=2)works (integer refit, 108 rows)AutoMFLESwithcross_validation(refit=True)still works (regression check)AutoTBATSwithcross_validation(refit=False)worksAutoTBATSwithcross_validation(refit=2)worksforward()directly returns validmeanandfittedvalues (no NaN)fit()Closes #911