Sampling in Python
James Chapman
Curriculum Manager, DataCamp
import matplotlib.pyplot as plt
plt.hist(coffee_boot_distn, bins=15)
plt.show()
import numpy as np
np.mean(coffee_boot_distn)
7.513452892
np.mean(coffee_boot_distn)
7.513452892
np.mean(coffee_boot_distn) - np.std(coffee_boot_distn, ddof=1)
7.497385709174466
np.mean(coffee_boot_distn) + np.std(coffee_boot_distn, ddof=1)
7.529520074825534
np.quantile(coffee_boot_distn, 0.025)
7.4817195
np.quantile(coffee_boot_distn, 0.975)
7.5448805
Implemented in Python with
from scipy.stats import norm
norm.ppf(quantile, loc=0, scale=1)
point_estimate = np.mean(coffee_boot_distn)
7.513452892
std_error = np.std(coffee_boot_distn, ddof=1)
0.016067182825533724
from scipy.stats import norm
lower = norm.ppf(0.025, loc=point_estimate, scale=std_error)
upper = norm.ppf(0.975, loc=point_estimate, scale=std_error)
print((lower, upper))
(7.481961792328933, 7.544943991671067)
Sampling in Python