Sktime: [BUG] Overlap of training and test window in SlidingWindowSplitter

Created on 20 Jan 2021  路  2Comments  路  Source: alan-turing-institute/sktime

Describe the bug

sktime/sktime/forecasting/model_selection/_split.py
Line 217 in 36f3cb1 test_window = split_point + fh - 1
The last element of training window and first element of test window overlaps when SlidingWindowSplitter's _split_windows function is called.

To Reproduce

from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_selection import (
    ForecastingGridSearchCV,
    SlidingWindowSplitter,
    temporal_train_test_split,
)

y = load_airline()
y_train, y_test = temporal_train_test_split(y, test_size=36)

fh = ForecastingHorizon(y_test.index, is_relative=False)
cv = SlidingWindowSplitter(step_length= 3, fh = list(range(3)), window_length= 20)

windows = cv._split_windows(y_train)
for i in list(windows)[:10]:
    print(i)

Expected behavior

(array([-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8,
-7, -6, -5, -4, -3, -2]), array([-1, 0, 1]))
(array([-17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5,
-4, -3, -2, -1, 0, 1]), array([2, 3, 4]))

Additional context

Versions

System:
python: 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0]
executable: /usr/bin/python3
machine: Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic

Python dependencies:
pip: 19.3.1
setuptools: 51.1.2
sklearn: 0.24.1
sktime: 0.5.2
statsmodels: 0.12.1
numpy: 1.19.5
scipy: 1.4.1
Cython: 0.29.21
pandas: 1.1.5
matplotlib: 3.2.2
joblib: 1.0.0
numba: 0.52.0
pmdarima: None
tsfresh: None

bug

All 2 comments

Thanks @koralturkk - good catch!

I'm not sure why this isn't caught by the existing unit tests. I'd appreciate a PR and unit test to catch this kind of error for the temporal CV splitters.

@mloning I will take a look into it while I work on the units tests for ExpandingWindowSplitter.

Was this page helpful?
0 / 5 - 0 ratings