ComenzarEmpieza gratis

Generating many bootstrap replicates

The function bootstrap_replicate_1d() from the video is available in your namespace. Now you'll write another function, draw_bs_reps(data, func, size=1), which generates many bootstrap replicates from the data set. This function will come in handy for you again and again as you compute confidence intervals and later when you do hypothesis tests.

For your reference, the bootstrap_replicate_1d() function is provided below:

def bootstrap_replicate_1d(data, func):
    return func(np.random.choice(data, size=len(data)))

Este ejercicio forma parte del curso

Statistical Thinking in Python (Part 2)

Ver curso

Instrucciones del ejercicio

  • Define a function with call signature draw_bs_reps(data, func, size=1).
    • Initialize an array, bs_replicates to hold all of the bootstrap replicates using np.empty().
    • Write a for loop to compute a replicate using bootstrap_replicate_1d() and stores the replicate in bs_replicates.
    • Return the array of replicates.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

def draw_bs_reps(data, func, size=1):
    """Draw bootstrap replicates."""

    # Initialize array of replicates: bs_replicates
    bs_replicates = ____

    # Generate replicates
    for i in ____:
        bs_replicates[i] = ____

    return bs_replicates
Editar y ejecutar código