Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-326

Chronological Holdout Split

Problem

Split a series into a training prefix and a test suffix that contains the last h observations. Return the pair as [train, test], preserving the original time order.

If h is not positive, the test part is empty. If h is at least the series length, the training part is empty.

Hint

Never shuffle time series; the test set must stay in the future of the training set.

Test cases

case 1
in: [[1,2,3,4,5],2]
expected: [[1,2,3],[4,5]]
case 2
in: [[1,2,3],0]
expected: [[1,2,3],[]]
case 3
in: [[1,2],5]
expected: [[],[1,2]]
case 4
in: [[],1]
expected: [[],[]]
Starter codePython
def chronological_holdout_split(series, h):
    # Your code here
    pass

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