Is there an equivalent of boot and boot.ci in python?
In R
I would do
library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)
Boot.py is an small set of tools to build simple scripts. Python3 only, and really small: 2Kb!
What is Bootstrap Sampling? The definition for bootstrap sampling is as follows : In statistics, Bootstrap Sampling is a method that involves drawing of sample data repeatedly with replacement from a data source to estimate a population parameter.
The bootstrap method is a resampling technique used to estimate statistics on a population by sampling a dataset with replacement. It can be used to estimate summary statistics such as the mean or standard deviation.
In statistics and machine learning, bootstrapping is a resampling technique that involves repeatedly drawing samples from our source data with replacement, often to estimate a population parameter. By “with replacement”, we mean that the same data point may be included in our resampled dataset multiple times.
I can point to specific bootstrap usage in python. I am assuming you are looking for similar methods for bootstrapping in python
as we do in R
.
import numpy as np
import bootstrapped.bootstrap as bs
import bootstrapped.stats_functions as bs_stats
mean = 100
stdev = 10
population = np.random.normal(loc=mean, scale=stdev, size=50000)
# take 1k 'samples' from the larger population
samples = population[:1000]
print(bs.bootstrap(samples, stat_func=bs_stats.mean))
>> 100.08 (99.46, 100.69)
print(bs.bootstrap(samples, stat_func=bs_stats.std))
>> 9.49 (9.92, 10.36)
The specific packages used here are bootstrapped.bootstrap
and bootstrapped.stats_functions
. You can explore more about this module here
There's also the resample
package available via pip
. Here's the Github page: https://github.com/dsaxton/resample.
Regarding your example you could do the following (there's also a ci_method
argument you can tweak for either the percentile, BCA or Studentized bootstrap interval):
from resample.bootstrap import bootstrap_ci
bootstrap_ci(a=data, f=bootfun, b=10000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With