Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-040

Bagging Feature Subset

Problem

Select k distinct feature indices at random (without replacement) from range(n_features) using a seeded shuffle.

Call random.seed(seed), shuffle the list of indices, take the first k, and return them sorted in ascending order.

Hint

Shuffle all indices, take a prefix, and sort the result.

Test cases

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

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