Skip to content

Instantly share code, notes, and snippets.

@vb100
Created June 14, 2018 22:10
Show Gist options
  • Save vb100/c76ac18e3a83e1720cdc182074b75023 to your computer and use it in GitHub Desktop.
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.
# 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