NumPy Poisson Distribution (Python Tutorial)

Poisson Distribution

This is a detailed tutorial of NumPy Poisson Distribution. Learn to implement Poisson Distribution in NumPy and visualize using Seaborn.

Poisson Distribution

This distribution is a discrete distribution in which we have a discrete set of data. This data is not in the continuous form of data. In this type of data, we have certain types of the specified value, and the outcomes can not be beyond these values.

This distribution helps us in calculating the probability of occurrence of an event. These events will take place at a certain specified time. As a result, we get to know about the occurrence of an event and the number of times the event will occur. Also, the event takes place in a particular time period, not before or after that time.

This distribution takes in these two parameters as input:

  • lam – this is the rate of occurrence of an event
  • size – it is the shape of the returned array.

Let u stake an example to understand it better:

# here first we will import the numpy package with random module
from numpy import random
# we will use method
x=random.poisson(lam=4,size=5)
#now we will print the graph
print(x)

Output:

[4 6 2 3 7]

Here in this example, we have given the rate of occurrence as four and the shape of the array as five. As a result, we get the following outcome.

let us visualize this data distribution with an example:

# here first we will import the numpy package with random module
from numpy import random
#here we ill import matplotlib 
import matplotlib.pyplot as plt 
#now we will import seaborn 
import seaborn as sns 
#we will plot a displot here 
sns.distplot(random.poisson(lam=3,size=500), kde=False) 
# now we have the plot printed 
plt.show()

Output:

Poisson Distribution Example 1

Here we get the visual distribution of the data by using poison distribution.

Difference between Normal, Binomial and Poisson

In a normal distribution, we have continuous data, whereas the other two distributions have binomial and Poisson have a discrete set of data. They can become similar when certain standard deviation and mean could match and also large ver n, and near-zero p is very much identical to the Poisson distribution because n*p is equal to lam.

Let us go through the example to see the difference:

# here first we will import the numpy package with random module 
from numpy import random 
#here we ill import matplotlib 
import matplotlib.pyplot as plt 
#now we will import seaborn 
import seaborn as sns 
#we will plot a displot here 
sns.distplot(random.normal(loc=50,scale=4,size=500), hist=False, label='normal') 
#we will plot a displot here 
sns.distplot(random.binomial(n=50,p=0.5,size=500), hist=False, label='binomial')
#we will plot a displot here 
sns.distplot(random.poisson(lam=5,size=500), hist=False, label='poisson')  
# now we have the plot printed 
plt.show()

Output:

Poisson Distribution Example 2

I hope you found this guide useful. If so, do share it with others who are willing to learn Numpy and Python. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *