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 predict method returns wrong predictions when n_samples>1 #1629

Closed
TueLindhart opened this issue Mar 7, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@TueLindhart
Copy link

Describe the bug
When I use the predict function with n_samples > 1, then it seems to return "delayed" predictions that not are offset from the latest series observation. The predictions seem to align with earlier observations in the training series.

To Reproduce

forecaster = ARIMA(p=0,d=1,q=0)
forecaster.fit(series=series,future_covariates=future_covariates_train)

y_pred1 = forecaster.predict(n=24,future_covariates=future_covariates_test,num_samples=1) # Correct offset
y_pred2 = forecaster.predict(n=24,future_covariates=future_covariates_test,num_samples=2) # Wrong offset 

The data used in array format:

series = array([12.9  , 12.9  , 12.9  , 12.9  , 12.9  , 12.9  , 12.9  , 12.9  ,
       12.9  , 12.9  , 12.9  , 12.9  , 12.925, 12.95 , 12.975, 13.   ,
       13.025, 13.05 , 13.075, 13.1  , 13.125, 13.15 , 13.175, 13.2  ,
       13.3  , 13.4  , 13.5  , 13.6  , 13.65 , 13.7  , 13.75 , 13.8  ,
       13.875, 13.95 , 14.025, 14.1  , 14.15 , 14.2  , 14.25 , 14.3  ,
       14.3  , 14.3  , 14.3  , 14.3  , 14.3  , 14.3  , 14.3  , 14.3  ])

future_covariates_train = array([[16.84177464, 77.        , 13.65      ],
       [16.85733716, 77.        , 13.4       ],
       [16.87269715, 77.        , 13.15      ],
       [16.88785423, 77.        , 12.9       ],
       [16.904009  , 77.25      , 12.625     ],
       [16.92115493, 77.5       , 12.35      ],
       [16.93928579, 77.75      , 12.075     ],
       [16.95839566, 78.        , 11.8       ],
       [16.97972589, 78.5       , 11.725     ],
       [17.00328543, 79.        , 11.65      ],
       [17.02908464, 79.5       , 11.575     ],
       [17.05713531, 80.        , 11.5       ],
       [17.08744904, 80.5       , 11.45      ],
       [17.12004015, 81.        , 11.4       ],
       [17.15492448, 81.5       , 11.35      ],
       [17.1921195 , 82.        , 11.3       ],
       [17.23163856, 82.5       , 11.3       ],
       [17.27350111, 83.        , 11.3       ],
       [17.31772833, 83.5       , 11.3       ],
       [17.3643432 , 84.        , 11.3       ],
       [17.41028977, 84.        , 11.3       ],
       [17.45557761, 84.        , 11.3       ],
       [17.50021616, 84.        , 11.3       ],
       [17.54421474, 84.        , 11.3       ],
       [17.58913722, 84.25      , 11.175     ],
       [17.63498688, 84.5       , 11.05      ],
       [17.68176728, 84.75      , 10.925     ],
       [17.72948236, 85.        , 10.8       ],
       [17.77811794, 85.25      , 10.775     ],
       [17.82767766, 85.5       , 10.75      ],
       [17.87816548, 85.75      , 10.725     ],
       [17.92958561, 86.        , 10.7       ],
       [17.98353051, 86.5       , 11.075     ],
       [18.04001078, 87.        , 11.45      ],
       [18.09903865, 87.5       , 11.825     ],
       [18.16062807, 88.        , 12.2       ],
       [18.22303155, 88.25      , 12.45      ],
       [18.28624752, 88.5       , 12.7       ],
       [18.35027463, 88.75      , 12.95      ],
       [18.41511178, 89.        , 13.2       ],
       [18.47355594, 88.25      , 13.15      ],
       [18.52587616, 87.5       , 13.1       ],
       [18.57232717, 86.75      , 13.05      ],
       [18.61315034, 86.        , 13.        ],
       [18.65023175, 85.5       , 12.75      ],
       [18.683676  , 85.        , 12.5       ],
       [18.71358437, 84.5       , 12.25      ],
       [18.74005494, 84.        , 12.        ]])

future_covariates_test = array([[18.76617668, 84.        , 11.85      ],
       [18.79195331, 84.        , 11.7       ],
       [18.8173885 , 84.        , 11.55      ],
       [18.84248586, 84.        , 11.4       ],
       [18.86723634, 84.        , 11.325     ],
       [18.8916446 , 84.        , 11.25      ],
       [18.91571521, 84.        , 11.175     ],
       [18.93945269, 84.        , 11.1       ],
       [18.9643633 , 84.25      , 11.225     ],
       [18.99044204, 84.5       , 11.35      ],
       [19.01768421, 84.75      , 11.475     ],
       [19.04608539, 85.        , 11.6       ],
       [19.07249807, 84.75      , 11.625     ],
       [19.09696678, 84.5       , 11.65      ],
       [19.11953511, 84.25      , 11.675     ],
       [19.14024571, 84.        , 11.7       ],
       [19.16210988, 84.23529412, 11.64117647],
       [19.18512517, 84.47058824, 11.58235294],
       [19.20928947, 84.70588235, 11.52352941],
       [19.23460093, 84.94117647, 11.46470588],
       [19.26105805, 85.17647059, 11.40588235],
       [19.28865963, 85.41176471, 11.34705882],
       [19.31740479, 85.64705882, 11.28823529],
       [19.34729295, 85.88235294, 11.22941176]])

Expected behavior
The offset of the first prediction should be close to the last entry in the training series.

System (please complete the following information):

  • Python version: 3.10.6
  • darts version 0.23.1

Additional context
Add any other context about the problem here.

@TueLindhart TueLindhart added bug Something isn't working triage Issue waiting for triaging labels Mar 7, 2023
@TueLindhart
Copy link
Author

I believe it is fixed by:

forecast = self.model.simulate(
               nsimulations=n,
               repetitions=num_samples,
               initial_state=self.model.states.predicted[-1, :],
               anchor="end", <-- Add this
               exog=future_covariates.values(copy=False)
               if future_covariates
               else None,
)

in darts.models.forecasting.arima.py

@madtoinou
Copy link
Collaborator

Hi @TueLindhart,

Thank you for spotting and fixing this bug, would you like to open a PR with the fix? If you don't have the time, I would be happy to do it for you.

@madtoinou madtoinou removed the triage Issue waiting for triaging label Jun 14, 2023
@TueLindhart
Copy link
Author

Sorry, I currently do not have time to do so. :-)

@madtoinou
Copy link
Collaborator

Fixed by #1893.

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

No branches or pull requests

2 participants