How to do it…

Run the following code in a Jupyter code cell:

from scipy.stats import norm
mmean, msdev = 70, 4.0
fmean, fsdev = 65, 3.5
mdist = norm(mmean, scale=msdev)
fdist = norm(fmean, scale=fsdev)
nm, nf = 2000, 1500
mdata = mdist.rvs(size=nm)
fdata = fdist.rvs(size=nf)
plt.figure(figsize=(12, 4))
plt.subplot(1,2,1)
plt.hist([mdata, fdata], bins=20,
label=['Males', 'Females'])
plt.legend()
plt.xlabel('Height (inches)')
plt.ylabel('Frequency')
plt.subplot(1,2,2)
plt.boxplot([mdata, fdata], patch_artist=True,
labels=['Males', 'Females'])
None

Running this code will generate the following graph:

The two graphs clearly display the characteristics of a normal distribution, with heights for the male population having a larger mean and standard deviation. The box plots also display the outliers in the distribution, according to the 1.5 IQR rule.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset