Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-321

Purged CV Train Indices

Problem

Return the training indices for a purged cross-validation split. Start from every index outside the test window [test_start, test_end), then purge earlier samples whose label horizon overlaps the window (i + horizon > test_start) and embargo samples in [test_end, test_end + embargo). Return the survivors sorted ascending, or [] when the bounds are invalid or outside [0, n].

Hint

Purge overlapping labels before the test window and embargo the period right after it.

Test cases

case 1
in: [10,4,6,2,1]
expected: [0,1,2,7,8,9]
case 2
in: [8,3,5,0,2]
expected: [0,1,2,7]
case 3
in: [5,0,5,1,1]
expected: []
case 4
in: [6,2,4,10,0]
expected: [4,5]
case 5
in: [5,4,3,1,0]
expected: []
Starter codePython
def purged_train_indices(n, test_start, test_end, horizon, embargo):
    # Your code here
    pass

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