Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-142

Seeded Dataset Split Indices

Problem

Split dataset indices into train and validation sets with a seeded shuffle.

Seed the random module, shuffle list(range(n)), then move int(round(n * val_ratio)) indices to validation and keep the rest in train. Return [sorted_train, sorted_val].

Hint

Seed first, shuffle once, then slice the shuffled index list.

Test cases

case 1
in: [5,0.4,42]
expected: [[0,2,4],[1,3]]
case 2
in: [6,0.5,1]
expected: [[0,1,4],[2,3,5]]
case 3
in: [1,1,7]
expected: [[],[0]]
case 4
in: [4,0,0]
expected: [[0,1,2,3],[]]
Starter codePython
def split_indices(n, val_ratio, seed):
    # Your code here
    pass

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