Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-258

Feature Bagging Indices

Problem

Split feature indices into random subsets. Call random.seed(seed), shuffle range(n_features), and cut it into consecutive chunks of size k.

Return each chunk sorted; a non-positive k returns [].

Hint

Random feature subsets decorrelate the trees in a forest.

Test cases

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

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