Skip to content

Fix Statsmodels future forecast horizon - #1608

Open
Li Jiang (thinkall) wants to merge 1 commit into
mainfrom
fix/statsmodels-large-numpy-forecast
Open

Li Jiang (thinkall) wants to merge 1 commit into
mainfrom
fix/statsmodels-large-numpy-forecast

Conversation

@thinkall

Copy link
Copy Markdown
Collaborator

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-based predict() remains unchanged for in-sample predictions, and the shared forecast() 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

Targeted validation:

python -m pytest test\automl\test_forecast.py::test_numpy_large test\automl\test_forecast.py::test_models test\automl\test_forecast.py::test_numpy test\automl\test_forecast.py::test_log_training_metric_ts_models -q --reruns 2 --reruns-delay 1

Result: 3 passed, 1 skipped.

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

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 first X.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-based predict() 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants