Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-021

Deterministic Train/Test Split

Problem

Split the ordered indices 0..n-1 into train and test sets without shuffling.

n_test = int(n * test_fraction) (floor) indices go to the test set at the end, and the rest go to train. Return [train_indices, test_indices] in ascending order.

Hint

Compute the test size with int(), then slice the index range.

Test cases

case 1
in: [10,0.2]
expected: [[0,1,2,3,4,5,6,7],[8,9]]
case 2
in: [5,0.5]
expected: [[0,1,2],[3,4]]
case 3
in: [7,0.3]
expected: [[0,1,2,3,4],[5,6]]
case 4
in: [4,0]
expected: [[0,1,2,3],[]]
Starter codePython
def train_test_split_ordered(n, test_fraction):
    # Returns [train_indices, test_indices]
    # Your code here
    pass

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