All problems
Grouped CV Fold Sizes
Problem
Compute the sample count of every fold in a grouped k-fold split. Sort the distinct groups and assign them to contiguous folds so the first (g % k) folds receive one extra group, where g is the number of groups. A fold's size is the total number of samples in its groups. Return [] when k <= 0.
Hint
Keeping every group inside one fold prevents the same entity leaking across train and validation.
Test cases
case 1
in: [["a","a","b","b","c","c"],2]
expected: [4,2]
case 2
in: [["a","a","a","b","c"],2]
expected: [4,1]
case 3
in: [["x","y"],5]
expected: [1,1,0,0,0]
case 4
in: [[],2]
expected: [0,0]
case 5
in: [["m","m"],0]
expected: []
Starter codePython
def grouped_fold_sizes(groups, k):
# Your code here
pass5 test cases · run your code against them in the editor