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

fix cross_validation results with uneven windows #989

Merged
merged 5 commits into from
May 4, 2024
Merged

Conversation

jmoralez
Copy link
Member

@jmoralez jmoralez commented May 2, 2024

The cross_validation method always produces the same number of windows for each serie, regardless of its size, so we may end up with times that the original serie doesn't have.

fcsts = np.full(
(self.dataset.n_groups * self.h * n_windows, len(cols)),
np.nan,
dtype=np.float32,
)

This conflicts with the definition of the cv_times function, which only keeps the windows that could be produced by a serie when performing cross validation, i.e. if a serie has 51 samples and we use window_size=10, step_size=10, then it can produce at most 5 windows (where the first window has 1 training sample)
https://github.com/Nixtla/utilsforecast/blob/fe357c49a3b3007256eb54bf586656dd5f3de2f6/utilsforecast/processing.py#L489

So we could end up with dataframes that had a different number of rows and perform a horizontal stack

fcsts_df = ufp.horizontal_concat([fcsts_df, fcsts])

which would produce a lot of rows with null values and place the forecasts in the wrong places.

This takes the times produced by the cv_times function and extracts the forecasts that correspond to those times from all the forecasts that were produced. Ideally we should make sure that we don't produce windows that don't exist in the first place to avoid also wasting compute when running inference on windows full of zeros.

Also fixes some failing tests by increasing the tolerance and reduces the max_steps in the BiTCN model to reduce the CI time.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jmoralez jmoralez marked this pull request as ready for review May 3, 2024 18:58
@jmoralez jmoralez requested review from AzulGarza and cchallu May 3, 2024 19:11
@jmoralez jmoralez added the fix label May 3, 2024
neuralforecast/core.py Show resolved Hide resolved
@jmoralez jmoralez merged commit b85b07d into main May 4, 2024
17 checks passed
@jmoralez jmoralez deleted the fix-uneven-cv branch May 4, 2024 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants