v9.1.1
Menu

Bootstrap Sample

easyFREEEnsemble MethodsMachine Learning 1

Generate a bootstrap sample (sampling with replacement) using a given list of random indices.

Given a dataset of nn items, a bootstrap sample draws nn items with replacement. To make this deterministic, you are given a list of indices to draw.

Return the selected items as a list.

Example

Input
data = ['a', 'b', 'c', 'd']
indices = [0, 2, 2, 1]
Output
['a', 'c', 'c', 'b']
Reasoning
  • The given dataset is data = ['a', 'b', 'c', 'd'] and the list of indices to draw is indices = [0, 2, 2, 1].
  • We use the indices to select items from the dataset with replacement, so the first index 0 corresponds to 'a', the second index 2 corresponds to 'c', the third index 2 again corresponds to 'c', and the fourth index 1 corresponds to 'b'.
  • The selected items are then combined into a list in the order they were drawn: ['a', 'c', 'c', 'b'].
  • The final output is this list of selected items.

Constraints

  • data: list of items
  • indices: list of integer indices (0 to len(data)-1, may repeat)
  • Return the items at the given indices

Learn this in

More from Machine Learning 1

solution.py

Test results

Sign in to run your code against the test cases.