Hướng dẫn dùng poisson pmf python


The Poisson distribution describes the probability of obtaining k successes during a given time interval.

If a random variable X follows a Poisson distribution, then the probability that X = k successes can be found by the following formula:

P(X=k) = λk * e– λ / k!

where:

  • λ: mean number of successes that occur during a specific interval
  • k: number of successes
  • e: a constant equal to approximately 2.71828

This tutorial explains how to use the Poisson distribution in Python.

How to Generate a Poisson Distribution

You can use the poisson.rvs(mu, size) function to generate random values from a Poisson distribution with a specific mean value and sample size:

from scipy.stats import poisson

#generate random values from Poisson distribution with mean=3 and sample size=10
poisson.rvs(mu=3, size=10)

array([2, 2, 2, 0, 7, 2, 1, 2, 5, 5])

How to Calculate Probabilities Using a Poisson Distribution

You can use the poisson.pmf(k, mu) and poisson.cdf(k, mu) functions to calculate probabilities related to the Poisson distribution.

Example 1: Probability Equal to Some Value

A store sells 3 apples per day on average. What is the probability that they will sell 5 apples on a given day? 

from scipy.stats import poisson

#calculate probability
poisson.pmf(k=5, mu=3)

0.100819

The probability that the store sells 5 apples in a given day is 0.100819.

Example 2: Probability Less than Some Value

A certain store sells seven footballs per day on average. What is the probability that this store sells four or less footballs in a given day?

from scipy.stats import poisson

#calculate probability
poisson.cdf(k=4, mu=7)

0.172992

The probability that the store sells four or less footballs in a given day is 0.172992.

Example 3: Probability Greater than Some Value

A certain store sells 15 cans of tuna per day on average. What is the probability that this store sells more than 20 cans of tuna in a given day?

from scipy.stats import poisson

#calculate probability
1-poisson.cdf(k=20, mu=15)

0.082971

The probability that the store sells more than 20 cans of tuna in a given day is 0.082971.

How to Plot a Poisson Distribution

You can use the following syntax to plot a Poisson distribution with a given mean:

from scipy.stats import poisson
import matplotlib.pyplot as plt

#generate Poisson distribution with sample size 10000
x = poisson.rvs(mu=3, size=10000)

#create plot of Poisson distribution
plt.hist(x, density=True, edgecolor='black')

Hướng dẫn dùng poisson pmf python

Additional Resources

An Introduction to the Poisson Distribution
5 Real-Life Examples of the Poisson Distribution
Online Poisson Distribution Calculator

What is the PMF of a Poisson distribution?

The PMF (probability mass function) of a Poisson distribution is given by: The can be read as: Poisson probability of k events in an interval. And the CDF (cumulative distribution function) of a Poisson distribution is given by: Now that we know some formulas to work with, let’s go through an example in detail.

How to use the Poisson distribution in Python?

The Poisson distribution describes the probability of obtaining k successes during a given time interval. If a random variable X follows a Poisson distribution, then the probability that X = k successes can be found by the following formula: P (X=k) = λk * e– λ / k! This tutorial explains how to use the Poisson distribution in Python.

What is Python?

Python là ngôn ngữ dành cho người mới: Python là một ngôn ngữ rất tốt dành cho những người mới, đặc biệt là dành cho các học sinh – sinh viên vì có cú pháp đơn giản, trong sáng, dễ học hơn so với các ngôn ngữ khác.

What is a Poisson process and how is it defined?

A Poisson process is defined by a Poisson distribution. What is a Poisson distribution? A Poisson distribution is a discrete probability distribution of a number of events occurring in a fixed interval of time given two conditions: Events occur with some constant mean rate.