Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-129

Expanding Window Splits

Problem

Generate expanding-window time series splits. For each t from initial_train to n-1, the training set is range(t) and the test set is [t].

Return the list of [train_indices, test_indices]; if initial_train is negative or at least n, return [].

Hint

The training window grows by one sample as the test point moves forward.

Test cases

case 1
in: [5,3]
expected: [[[0,1,2],[3]],[[0,1,2,3],[4]]]
case 2
in: [4,1]
expected: [[[0],[1]],[[0,1],[2]],[[0,1,2],[3]]]
case 3
in: [3,3]
expected: []
case 4
in: [3,4]
expected: []
Starter codePython
def expanding_window_splits(n, initial_train):
    # Returns list of [train_indices, test_indices]
    # Your code here
    pass

4 test cases · run your code against them in the editor