File size: 478 Bytes
798602c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# stats/inference/pi_bootstrap.py

import numpy as np


def pi_bootstrap(

    *,

    data,

    alpha,

    B,

):
    """

    Bootstrap prediction interval:

    average of bootstrap quantiles.

    """
    n = len(data)

    boot_intervals = np.array([
        np.quantile(
            np.random.choice(data, size=n, replace=True),
            [alpha / 2, 1 - alpha / 2],
        )
        for _ in range(B)
    ])

    return boot_intervals.mean(axis=0)