Numpy Random Poisson Distribution

The  NumPy random Poisson function generates random numbers following a Poisson distribution. In this article, we will examine what Poisson distribution is and how to use the NumPy random Poisson function.

Numpy Random Poisson Distribution



What is a Poisson Distribution?

The Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time or space, assuming that the events are independent and that the average rate of occurrence is constant.

The Poisson distribution is often used to model random occurrences, such as:

  • Number of customers who arrive at a store.
  • Number of cars that pass through a toll booth.
  • Number of phone calls received by a call center.

The Poisson distribution is characterized by a single parameter, which represents the average rate of occurrence of the events.

This parameter is denoted by λ (lambda) and is also equal to the variance of the distribution.

The probability mass function (PMF) of the Poisson distribution is given by:

P(mrX = k) = (e^(-λ) * λ^k) / k!

where mrX is the random variable representing the number of events, k is a non-negative integer, e is the base of the natural logarithm, and k! is the factorial of k.


NumPy Random Poisson Function

A Numpy random poisson function is a discrete distribution and is a part of the NumPy.random module and is used to generate random numbers following a Poisson distribution.

It estimates how many times an event could occur in a certain period of time.

For example, what is the chance that a person will eat four meals a day if he eats three meals daily?

A parameter of this function is the following:

 

ParametersOverview
lamThe number of instances or the rate of events, for example. Three in the situation above.
sizeThis is how the array will be arranged when it is retrieved.

 

Syntax

numpy.random.poisson(lam=1.0, size=None)

where lam is the expected value of the Poisson distribution, and size is the shape of the output array.

The function returns an array of random integers representing the number of events that occur in a fixed interval of time or space.

The values in the array are generated independently of each other and follow a Poisson distribution with parameter λ.

Let’s look at below examples:

Create a random 1×30 distribution for instance 3:

Example: 

from numpy import random mrx = random.poisson(lam=3, size=30) print(mrx)

Randomly distribute the outcomes of 5 as follows:

Example: 

from numpy import random mrx = random.poisson(lam=5, size=15) print(mrx)

Visualization of Poisson Distribution

To visualize NumPy Random Poisson distribution, we can use Python’s matplotlib library.

We will generate a range of values for the number of occurrences, and then calculate the probability mass function for each value using the Poisson distribution formula.

Finally, we will plot the results as a histogram.

Implementation of visual representation:

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.poisson(lam=3, size=30), kde=False) pt.show()

Apply the below code with kde = True:

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.poisson(lam=5, size=15), kde=True) pt.show()

Difference Between Normal and Poisson Distribution

In Numpy random poisson, the normal distribution is continuous, while the poisson distribution is discrete.

When the poisson distribution grows wide and long enough, it will become almost identical to the normal distribution with only a few standard deviations and means.

Differences between normal and Poisson distributions can be summarized as follows:

  1. Normal distribution is used for continuous data, while Poisson distribution is used for count data.
  2. Normal distribution has two parameters (mean and standard deviation), while Poisson distribution has one parameter (average rate of occurrence).
  3. Normal distribution is symmetric around the mean, while Poisson distribution is skewed to the right if the average rate of occurrence is small.
  4. Normal distribution has a continuous probability density function, while Poisson distribution has a discrete probability mass function.
  5. Normal distribution measures the spread of the data using the standard deviation, while Poisson distribution has a fixed variance equal to the average rate of occurrence.

The below two examples will ensure you understand the difference between Normal and Poisson distribution:

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.normal(loc=2, scale=5, size=100), hist=False, label='normal') sbn.distplot(random.poisson(lam=3, size=30), hist=False, label='poisson') pt.show()

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.normal(loc=15, scale=45, size=5), hist=True, kde = False, label='normal') sbn.distplot(random.poisson(lam=5, size=2), hist=True, kde = False, label='poisson') pt.show()

Difference Between Poisson and Binomial Distribution

A very slight difference is found between the binomial and poisson distributions, and it is that the binomial distribution is applied for discrete tests, while the poisson distribution is utilized for continuous tests.

However, when n is very high and p is close to 0, binomial distribution is almost equal to poisson distribution, so that n + p is approximately identical to lam.

Differences between Poisson and binomial distributions can be summarized as follows:

  • Poisson distribution is used for count data, while binomial distribution is used for the number of successes in a fixed number of trials.
  • Poisson distribution has one parameter (average rate of occurrence), while binomial distribution has two parameters (probability of success and number of trials).
  • Poisson distribution is skewed to the right if the average rate of occurrence is small, while binomial distribution is symmetric if p=0.5.
  • Poisson distribution has a PMF that depends only on the rate parameter, while binomial distribution has a PMF that depends on both the probability of success and the number of trials.
  • Poisson distribution is used to approximate the binomial distribution when the number of trials is large and the probability of success is small.

Here are two examples that demonstrate the distinction between the Poisson and Binomial distributions:

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.binomial(n=20, p=0.3, size=50), hist=False, label='binomial') sbn.distplot(random.poisson(lam=3, size=15), hist=False, label='poisson') pt.show()

Example: 

from numpy import random import matplotlib.pyplot as pt import seaborn as sbn sbn.distplot(random.binomial(n=10, p=0.01, size=7), hist=True, kde = False, label='binomial') sbn.distplot(random.poisson(lam=13, size=2), hist=True, kde = False, label='poisson') pt.show()

Conclusion

The NumPy random Poisson function is useful for generating random numbers following a Poisson distribution.

It can be used in a variety of applications, such as simulating customer arrivals, phone calls, or car accidents.

By understanding the Poisson distribution and how to use the NumPy random Poisson function, we can better analyze and model random occurrences in our data.

We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

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