Confidence Interval of Mean
Learn, calculate, and compare the confidence interval of the mean using the classical and bootstrapped approaches.
SciPy is another very convenient library in the Python ecosystem for data science. It is a collection of mathematical algorithms and convenience functions built on NumPy. We can use stats.norm()
from the library to accomplish this task of computing the confidence interval using the classical formula for means.
Classical approach
We have already inserted z-scores for the 95% confidence level in the formula above. Let's reconfirm the values of the z-score using the ppf
module available in scipy.stats.norm()
. We'll be using this to get percentiles for our confidence interval formula.
Press + to interact
from scipy import stats # import the library# ppf() -- Percent point function (inverse of ``cdf`` -- cumulative distribution function)print("So, the values of upper and lower z-scores for 95% confidence level are:",stats.norm().ppf(q = 0.025),"&", stats.norm().ppf(q = 0.975)) # RV -- Random variable
Let's move on and compute the confidence interval ...
Access this course and 1400+ top-rated courses and projects.