Bootstrap Sample
Generate a bootstrap sample (sampling with replacement) using a given list of random indices.
Given a dataset of items, a bootstrap sample draws items with replacement. To make this deterministic, you are given a list of indices to draw.
Return the selected items as a list.
Example
data = ['a', 'b', 'c', 'd'] indices = [0, 2, 2, 1]
['a', 'c', 'c', 'b']
datais the original dataset: items,'a','b','c','d', sitting at positions to .indicesis a pre-drawn list of positions , standing in for the random draws so the result is reproducible.- Draw simply returns the item at position , i.e. output: position gives
'a', position gives'c', position again gives'c', and position gives'b'. - Keeping the draws in order gives
['a', 'c', 'c', 'b']— the same length as the original, holding the items themselves (strings here), not their positions. - Notice that
'c'appears twice while'd'never appears: that is what sampling with replacement means. A drawn item stays available for later draws, so some items repeat and others are left out. - Here of the distinct items made it in; for large a bootstrap sample contains about of them, and the missing ones are called out-of-bag.
Constraints
- data: list of items
- indices: list of integer indices (0 to len(data)-1, may repeat)
- Return the items at the given indices