Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boot() equivalent in python?

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)
like image 310
HappyPy Avatar asked Mar 27 '18 20:03

HappyPy


People also ask

What is python boot?

Boot.py is an small set of tools to build simple scripts. Python3 only, and really small: 2Kb!

What does bootstrapping mean for Python?

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.

When should I use bootstrapping?

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.

What is bootstrapping machine learning?

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.


2 Answers

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

like image 152
CodeHunter Avatar answered Oct 03 '22 18:10

CodeHunter


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)
like image 35
dsaxton Avatar answered Oct 03 '22 17:10

dsaxton