Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] VAR cannot predict quantiles when alpha is 0.5 #4742

Closed
yarnabrina opened this issue Jun 22, 2023 · 1 comment · Fixed by #6441
Closed

[BUG] VAR cannot predict quantiles when alpha is 0.5 #4742

yarnabrina opened this issue Jun 22, 2023 · 1 comment · Fixed by #6441
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects

Comments

@yarnabrina
Copy link
Collaborator

Describe the bug

VAR is unable to predict 0.5 quantile using predict_quantiles, i.e. median.

To Reproduce

from sktime.datasets import load_longley
_, y = load_longley()

from sktime.forecasting.var import VAR
forecaster = VAR().fit(y)

forecaster.predict_quantiles(fh=[1, 2, 3], alpha=[0.025, 0.5, 0.975])

Expected behavior

No error. Currently it fails with the following:

ValueError: alpha must be between 0 and 1

Additional context

I understand this should be same as predict, but I think it should still be able to predict as quantile nevertheless. 0.5 seems to work for AutoETS, AutoARIMA, StatsForecastAutoARIMA.

Versions

>>> from sktime import show_versions; show_versions()

System:
    python: 3.9.16 (main, Mar  8 2023, 14:00:05)  [GCC 11.2.0]
executable: /path/to/venv/bin/python
   machine: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

Python dependencies:
          pip: 23.1.2
       sktime: 0.19.2
      sklearn: 1.2.2
       skbase: 0.4.0
        numpy: 1.24.3
        scipy: 1.10.1
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
  statsmodels: 0.13.5
        numba: 0.57.1
     pmdarima: 2.0.3
      tsfresh: 0.20.0
   tensorflow: 2.12.0
tensorflow_probability: 0.19.0
>>> 
@yarnabrina yarnabrina added bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting labels Jun 22, 2023
@yarnabrina yarnabrina added this to Needs triage & validation in Bugfixing via automation Jun 22, 2023
@fkiraly
Copy link
Collaborator

fkiraly commented Jun 22, 2023

I understand this should be same as predict

Not in general, as the predictive median (predict_quantiles with 0.5) and predictive mean (from predict) may differ, but in this specific case they should indeed agree, since VAR assumes normal predictive distributions which happen to have this property.

fkiraly pushed a commit that referenced this issue May 25, 2024
… (#6441)

#### Reference Issues/PRs
Fixes #4742


#### What does this implement/fix? Explain your changes.
Previously, VAR produced an error when predicting quantiles with an
alpha of 0.5. This issue arose because alpha was converted to a coverage
of 1.0 in `_base`, which was then reconverted to an alpha ("internal
alpha") of 1.0 inside VAR's `_predict_interval`. An internal alpha of
1.0 is outside the acceptable range (0.0 to 1.0 exclusive) for
statsmodels VAR.

This change hackily coerces an internal alpha of 1.0 to 0.99999 to avoid
this error.
Bugfixing automation moved this from Needs triage & validation to Fixed/resolved May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects
Bugfixing
Fixed/resolved
Development

Successfully merging a pull request may close this issue.

2 participants