لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Python Data Science Poisson Data Distribution

Poisson Distribution is a Discrete Distribution: It estimates how many times an event can happen in a specified time.

e.g. If someone eats twice a day what is probability he will eat thrice?

It has following two parameters.

1. lam - rate or known number of occurences e.g. 2 for above problem.

2. size - The shape of the returned array.

Example 1: Generate a random 1x15 distribution for occurence 2.

Code

from numpy import random

x = random.poisson(lam=2, size=15)

print(x)

the output will be

[2 1 1 1 0 0 1 4 3 0 3 1 1 1 2]

Note: The output may differ everytime the code is run as it is generated at random.

Visualization of Poisson Distribution

Example 2

Code

from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(random.poisson(lam=2, size=10000), kde=False)

plt.show()

the output will be


What is the Difference Between Normal and Poisson Distribution?

Normal distribution is continous whereas poisson is discrete. but we can see that similar to binomial for a large enough poisson distribution it will become similar to normal distribution with certain std dev and mean.

Example 3

Code

from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(random.normal(loc=50, scale=7, size=10000), hist=False)

sns.distplot(random.poisson(lam=50, size=10000), hist=False)

plt.show()

the output will be


In the example above we draw the plot with 10000 data points and can observe from the fig that both the curve viz Normal distribution and Poisson distribution are displaying alot of similarities.

What is the Difference Between Poisson and Binomial Distribution?

Binomial distribution is for discrete trials, whereas poisson distribution is for continuous trials.

But for very large n and near-zero p binomial distribution is near identical to poisson distribution such that n * p is nearly equal to lam.

Example 4

Code

from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(random.binomial(n=1000, p=0.01, size=10000), hist=False)
sns.distplot(random.poisson(lam=10, size=10000), hist=False)

plt.show()

the output will be


In the example above we draw the plot with 10000 data points and can observe from the fig that both the curve viz Binomial distribution and Poisson distribution are displaying alot of similarities.