Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-120

Out-of-Bag Indices

Problem

Generate out-of-bag indices for bootstrap rounds. For each round draw n indices with replacement using random.seed(seed) and random.randrange(n); the OOB indices are the sorted indices never drawn that round.

Return one sorted list per round; n = 0 yields empty lists.

Hint

Track the set of indices drawn in each bootstrap round, then collect the complement.

Test cases

case 1
in: [5,3,42]
expected: [[3,4],[2,3],[2,4]]
case 2
in: [3,2,7]
expected: [[2],[1]]
case 3
in: [4,1,0]
expected: [[1]]
case 4
in: [0,2,1]
expected: [[],[]]
Starter codePython
import random
def out_of_bag_indices(n, num_rounds, seed):
    # Your code here
    pass

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