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] ForecastX is failing with forecaster_X_exogeneous="complement" #6405

Closed
yarnabrina opened this issue May 10, 2024 · 1 comment · Fixed by #6433
Closed

[BUG] ForecastX is failing with forecaster_X_exogeneous="complement" #6405

yarnabrina opened this issue May 10, 2024 · 1 comment · Fixed by #6433
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects

Comments

@yarnabrina
Copy link
Collaborator

Reproducible Code

from sktime.datasets import load_longley

y, X = load_longley()

cols_to_forecast = ["GNPDEFL", "GNP"]
fh = [1, 2, 3, 4]

from sktime.split import temporal_train_test_split

y_train, _, X_train, X_test = temporal_train_test_split(y, X, test_size=max(fh))

from sktime.forecasting.arima import ARIMA

forecaster = ARIMA()

from sktime.forecasting.compose import ForecastX

pipeline = ForecastX(
    forecaster.clone(),
    forecaster_X=forecaster.clone(),
    columns=cols_to_forecast,
    forecaster_X_exogeneous="complement",
)

pipeline.fit(y_train, X=X_train, fh=fh)

pipeline.predict(X=X_test.drop(columns=cols_to_forecast))

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/env/lib/python3.10/site-packages/sktime/forecasting/base/_base.py", line 448, in predict
    y_pred = self._predict(fh=fh, X=X_inner)
  File "/path/to/env/lib/python3.10/site-packages/sktime/forecasting/compose/_pipeline.py", line 1609, in _predict
    X = self._get_forecaster_X_prediction(fh=fh, X=X)
  File "/path/to/env/lib/python3.10/site-packages/sktime/forecasting/compose/_pipeline.py", line 1559, in _get_forecaster_X_prediction
    X_for_fcX = self._get_X_for_fcX(X)
  File "/path/to/env/lib/python3.10/site-packages/sktime/forecasting/compose/_pipeline.py", line 1586, in _get_X_for_fcX
    X_for_fcX = X.drop(columns=self.columns)
  File "/path/to/env/lib/python3.10/site-packages/pandas/core/frame.py", line 5581, in drop
    return super().drop(
  File "/path/to/env/lib/python3.10/site-packages/pandas/core/generic.py", line 4788, in drop
    obj = obj._drop_axis(labels, axis, level=level, errors=errors)
  File "/path/to/env/lib/python3.10/site-packages/pandas/core/generic.py", line 4830, in _drop_axis
    new_axis = axis.drop(labels, errors=errors)
  File "/path/to/env/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 7070, in drop
    raise KeyError(f"{labels[mask].tolist()} not found in axis")
KeyError: "['GNPDEFL', 'GNP'] not found in axis"

Version

System:
    python: 3.10.13 (main, Sep 11 2023, 08:39:02) [Clang 14.0.6 ]
executable: /path/to/env/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
          pip: 24.0
       sktime: 0.29.0
      sklearn: 1.4.2
       skbase: 0.7.7
        numpy: 1.26.4
        scipy: 1.13.0
       pandas: 2.2.2
   matplotlib: 3.8.4
       joblib: 1.4.0
        numba: 0.59.1
  statsmodels: 0.14.2
     pmdarima: 2.0.4
statsforecast: 1.7.4
      tsfresh: None
      tslearn: None
        torch: None
   tensorflow: None
tensorflow_probability: None

Note

If forecaster_X_exogeneous="complement" is removed from the reproducible code above, it starts working.

@yarnabrina yarnabrina added bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting labels May 10, 2024
@fkiraly fkiraly added this to Needs triage & validation in Bugfixing via automation May 10, 2024
@fnhirwa
Copy link
Contributor

fnhirwa commented May 15, 2024

I can confirm the bug, is reproducible on macOS, python: 3.9.18 on the main branch
I am going to start looking into this item.

@yarnabrina yarnabrina moved this from Needs triage & validation to Reproduced/confirmed in Bugfixing May 15, 2024
@fkiraly fkiraly moved this from Reproduced/confirmed to Investigating in Bugfixing May 15, 2024
Bugfixing automation moved this from Investigating to Fixed/resolved May 23, 2024
yarnabrina pushed a commit that referenced this issue May 23, 2024
)

<!--
Welcome to sktime, and thanks for contributing!
Please have a look at our contribution guide:
https://www.sktime.net/en/latest/get_involved/contributing.html
-->

#### Reference Issues/PRs
<!--
Example: Fixes #1234. See also #3456.

Please use keywords (e.g., Fixes) to create link to the issues or pull
requests
you resolved, so that they will automatically be closed when your pull
request
is merged. See
https://github.com/blog/1506-closing-issues-via-pull-requests.
If no issue exists, you can open one here:
https://github.com/sktime/sktime/issues
-->
fixes #6405

#### What does this implement/fix? Explain your changes.
<!--
A clear and concise description of what you have implemented.
-->
The issue was the way we were handling the complementation of the
columns.

#### PR checklist

##### For all contributions
- [x] The PR title starts with either [ENH], [MNT], [DOC], or [BUG].
[BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving
code, [DOC] - writing or improving documentation or docstrings.


<!--
Thanks for contributing!
-->
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