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] ARIMA future covariates not working #843

Closed
Japsz opened this issue Mar 11, 2022 · 6 comments · Fixed by #858
Closed

[BUG] ARIMA future covariates not working #843

Japsz opened this issue Mar 11, 2022 · 6 comments · Fixed by #858
Assignees
Labels
bug Something isn't working

Comments

@Japsz
Copy link

Japsz commented Mar 11, 2022

Describe the bug
ARIMA model is not letting me introduce exogenous variables into the model.

To Reproduce

df = pd.DataFrame([[1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [2,3], [3,4], [4,5], [5, 4], [3, 5], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4], [4,5], [5, 4], [3, 5], [1,2], [2,3], [3,4`], [4,`5], [5, 4], [3, 5]], columns=['target', 'covar'])
df.index = pd.RangeIndex(start=0, stop=len(df))

series = TimeSeries.from_dataframe(df, None, ['target', 'covar'])
train, test = train_test_split(series, test_size=0.2)

arima = ARIMA(p=1, d=1, q=1)
arima.fit(train['target'], future_covariates=series['covar'])
preds = arima.predict(len(test['target']), future_covariates=series['covar'])
[2022-03-11 17:07:28,770] ERROR | darts.models.forecasting.forecasting_model | ValueError: For the given forecasting horizon 'n=10', the provided 'future_covariates' series must contain at least the next 'n=10' time steps/indices after the end of the target 'series' that was used to train the model.

Expected behavior
I'm expecting this to work since I'm making sure that there's already at least n point after the training series ends.

System (please complete the following information):

  • Python version: 3.8.5
  • darts version 0.17.1

Additional context
I've been debugging a lot and seems that the internal slicing will always give a future covariate series that's one less than the prediction needs (when freq is 1), hence throwing the error.
in darts/models/forecasting/forecasting_model.py line 1183

future_covariates = future_covariates[
                start : start + (n - 1) * self.training_series.freq
            ]`
@Japsz Japsz added bug Something isn't working triage Issue waiting for triaging labels Mar 11, 2022
@Japsz
Copy link
Author

Japsz commented Mar 14, 2022

Can someone confirm if this is intended or not? Just wanna make sure I'm not doing something wrong with my code

@dennisbader
Copy link
Collaborator

Hi @Japsz and thanks for pointing this out.

You are right, the slicing only correctly works for DatetimeIndex and not a RangeIndex.

We need to fix this

@dennisbader dennisbader removed the triage Issue waiting for triaging label Mar 15, 2022
@DeastinY
Copy link

I've run into the same error today. Good timing 😁

@parshinsh
Copy link

I'm still getting the error of RangeIndex for ARIMA and VARIMA.

@dennisbader
Copy link
Collaborator

Which darts version are you using?
Please share the error message along with a minimal code snippet to reproduce the issue, thanks!

@yigitcancomlek
Copy link

yigitcancomlek commented Jul 11, 2023

Seems like this issue still persists for the ARIMA (ARMA) Model. I am still getting the same error with the below code

train_ts, val_ts= target_ts.split_before(train_cutoff) #40 samples for training # 150 samples for validation
train_val_cov  = covariates_ts; # all training and validation covariates (190x4)

model = ARIMA(p=1,d = 0,q=1)

model.fit(series = train_ts,
              future_covariates = covariates_ts)

predictions = model_ts.predict(n=150
              series=train_ts,  
              future_covariates=covariates_ts,
              num_samples = 100)

gives me the below error. Please let me know if I am making any mistake but if not, I believe the issue still persists. I have u8darts-all 0.24.0 downloaded in my conda environment

ValueError: Provided exogenous values are not of the appropriate shape. Required (110, 9), got (150, 9).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants