All problems
Oversampling Indices
Problem
Compute extra indices needed to oversample every class up to the majority count. Call random.seed(seed) and, for each class in sorted label order, draw random existing indices of that class with random.randrange until the shortfall is filled.
Return the extra indices sorted ascending; no extras returns [].
Hint
Duplicate existing minority indices (with replacement) until each class matches the majority count.
Test cases
case 1
in: [["a","a","b"],42]
expected: [2]
case 2
in: [[0,0,1,1,2],7]
expected: [4]
case 3
in: [[0,1],0]
expected: []
case 4
in: [["x","x","x","y","y","z"],1]
expected: [3,5,5]
Starter codePython
import random
def oversample_indices(labels, seed):
# Your code here
pass4 test cases · run your code against them in the editor