📘
Bootstrap Sample
EasyEnsemble Methods
Generate a bootstrap sample (sampling with replacement) using a given list of random indices.
Given a dataset of n items, a bootstrap sample draws n 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 isindices = [0, 2, 2, 1]. - We use the indices to select items from the dataset with replacement, so the first index
0corresponds to'a', the second index2corresponds to'c', the third index2again corresponds to'c', and the fourth index1corresponds 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
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.