Created
June 14, 2018 22:10
-
-
Save vb100/c76ac18e3a83e1720cdc182074b75023 to your computer and use it in GitHub Desktop.
Relationship between Binomial and Poisson distributions You just heard that the Poisson distribution is a limit of the Binomial distribution for rare events.
This file contains 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
# Draw 10,000 samples out of Poisson distribution: samples_poisson | |
samples_poisson = np.random.poisson(10, size = 10000) | |
# Print the mean and standard deviation | |
print('Poisson: ', np.mean(samples_poisson), | |
np.std(samples_poisson)) | |
# Specify values of n and p to consider for Binomial: n, p | |
n = [20, 100, 1000] | |
p = [0.5, 0.1, 0.01] | |
# Draw 10,000 samples for each n,p pair: samples_binomial | |
for i in range(3): | |
samples_binomial = np.random.binomial(n[i], p[i], size = 10000) | |
# Print results | |
print('n =', n[i], 'Binom:', np.mean(samples_binomial), | |
np.std(samples_binomial)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment