Computing Bootstrap estimates in Python

Venkatesh Gandi
2 min readDec 27, 2020

Bootstrapping is one of the re-sampling methods. It is often used as an alternative to statistical inference based on the assumption of a parametric model when that assumption is in doubt, or where parametric inference is impossible or requires complicated formulas for the standard errors. Also used for constructing hypothesis tests, confidence intervals of a population parameter like a mean, median, proportion.

Bootstrap Samples
Photo by Steven Kamenar on Unsplash
  • Inference about a population from sample data (sample → population(treats sample as population)) can be modeled by resampling(SRSWR) the sample data and performing inference about a sample from resampled data (resampled → sample). In bootstrap-resamples, the ‘population’ is in fact the sample, and this is known; hence the quality of inference of the ‘true’ sample from resampled data (resampled → sample) is measurable.
  • The only assumption to perform the bootstrapping is “the sample you have will exhibit the characteristics of population”.

let’s see how to get confidence intervals of a population parameter(Mean in our case) using bootstrapping.

Sample python code to get bootstrap Estimates

The obtained sampling distribution of mean looks like this

Sampling distribution of a statistic (mean in this case)

Easy way to get bootstrap estimate in python

s = np.random.choice(sample_, size=(n_iterations,n_size)) 
bootstrap_mean_estimates=s.mean(axis=0)
plt.hist(bootstrap_mean_estimates)
plt.title("Empirical distribution of sample mean",size=15)
plt.xlabel("Sample Mean",size=15)
plt.ylabel("Number of samples",size=15)
plt.show()

To get access to the complete code. Consider this GitHub link.

Before you leave

Give your feedback & suggestions to make this content more better. Your inputs are valuable.

To know about me, see my LinkedIn profile.

--

--

Venkatesh Gandi

Aspiring Data Scientist | Data Science and Machine Learning enthusiast | Love to connect with the people who are on the same path