Fix Statsmodels future forecast horizon - #1608
Open
Li Jiang (thinkall) wants to merge 1 commit into
Open
Li Jiang (thinkall) wants to merge 1 commit into
Li Jiang (thinkall) wants to merge 1 commit into
Conversation
Use positional step-based forecasting for future-only frames so statsmodels does not misinterpret datetime boundaries as a large positional range. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c6079966-3972-44ff-9f80-7b42cc2d00b5
Li Jiang (thinkall)
left a comment
Collaborator
Author
There was a problem hiding this comment.
Self-authored PR, so GitHub does not permit me to approve or request changes. One blocking issue found:
flaml/automl/time_series/ts_model.py:358-362: the new path ignores the requested timestamps and always returns the firstX.shape[0]periods immediately after training. If the requested future frame begins after a gap, it silently returns forecasts for the wrong dates. Preserve date-basedpredict()for delayed starts, or forecast through the skipped offset and slice; exogenous models must also account for every intervening step. Add a regression test for a noncontiguous/delayed future start across supported index types.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The future-horizon boundary check must use the model’s training end date.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR updates Statsmodels forecasting to avoid incorrect future horizons in Statsmodels 0.15.
Changes:
- Uses step-based
forecast()for future prediction frames. - Preserves date-based
predict()for other predictions. - Reuses preprocessed exogenous features.
File summaries
| File | Summary |
|---|---|
flaml/automl/time_series/ts_model.py |
Adds future-horizon forecasting logic. Moderate issue (3 votes): the boundary check uses the dataset end date instead of the model training end date, so the fix may be bypassed for holdout/CV data. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| exog = self._preprocess(X[self.regressors]) | ||
| forecast = self._model.predict(start=start, end=end, exog=exog.values, **kwargs) | ||
| exog = self._preprocess(X[self.regressors]).values if len(self.regressors) else None | ||
| if self.end_date is not None and start > self.end_date: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
Statsmodels 0.15 can interpret future datetime boundaries as positional indices when an ARIMA/SARIMAX model does not retain a supported date index. In
test_numpy_large, that turned a 10-row validation horizon into 59,990 out-of-sample steps and rejected the 10-row exogenous feature matrix.Use step-based
forecast()for prediction frames that begin after the estimator's training end date. Date-basedpredict()remains unchanged for in-sample predictions, and the sharedforecast()API preserves compatibility with ARIMA, SARIMAX, Holt-Winters, and simple forecasters.Failed job: https://github.com/microsoft/FLAML/actions/runs/35058894402/job/104684468013
Related issue number
N/A
Checks
test_numpy_largeis the existing regression coverage.)Targeted validation:
Result: 3 passed, 1 skipped.