Created
February 1, 2018 03:55
-
-
Save jrjames83/e37bba221e4de5689aa8dc6f82012548 to your computer and use it in GitHub Desktop.
Python Central Limit Theorem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import random | |
| # Create a parent distribution, from the gamma family | |
| shape, scale = 2., 2. # mean=4, std=2*sqrt(2) | |
| s = np.random.gamma(shape, scale, 100000) | |
| print(np.mean(s)) | |
| import matplotlib.pyplot as plt | |
| import scipy.special as sps | |
| plt.hist(s) | |
| plt.show() | |
| # The distribution of the means from the sampled groups is normally distributed | |
| samples = [ np.mean(random.choices(s, k=20)) for _ in range(1000) ] | |
| plt.hist(samples) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment