Poisson Probability
Tags: datascience, beginners, python, machinelearning
Published: 2020-10-04 22:40:25

###**Binomial vs Poisson probability**

When we know the frequency or an average number of successes/failures, and we are not particularly concerned with the total number of the events. Because the process is continuous or the number is very big. So, instead of using the binomial distribution for probability calculation, we can apply the Poisson probability mass function as it approximates well for smaller success/failure probabilities and a bigger number of events.

Here is the Poisson pmf:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wh6m59dsdmxam0orsm9v.png)

Where parameter λ>0 is a mean and x=0,1,2,... 

###**Examples**

Being an enthusiast of practical learning myself, I would like to show the application of Poisson distribution on examples.

**Problem 1** 
Customers arrive at a travel agency at a mean rate of 11 per hour. Assuming that the number of arrivals per hour has a Poisson distribution, give the probability that more than 10 customers arrive in a given hour. 
(Source: PROBABILITY AND STATISTICAL INFERENCE, 9th Edition, Robert V. Hogg, et. al.)
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b9kt0by774cmub4ktnm0.png)


To avoid mistakes I used Python to make calculation:

```python
# Solution:
    
# cumulative probability X <=10 
cumul_prob = poisson.cdf(10,11) # X<=10, lambda = 11

# probabiliy of X>=11:
1- cumul_prob
```

**Problem 2**

An airline always overbooks if possible. A particular plane has 95 seats on a flight in which a ticket sells for $300. The airline sells 100 such tickets for this flight.
(a) If the probability of an individual not showing up is 0.05, assuming independence, what is the probability that the airline can accommodate all the passengers who do show up? 
(Source: PROBABILITY AND STATISTICAL INFERENCE, 9th Edition, Robert V. Hogg, et. al.)


Here we can use binomial pmf or Poisson pmf as an approximate solution, where λ=p*n = 0.05*100=5.

To accommodate all passengers, it is required that out of 100 booked tickets 5 and more passengers not to show up.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/u7bzzbwqvdebe7mn27or.png)

```python
# Solution:
# Here I will use Poisson distribution as a 
# good approximation of binomial distribution as n=100, and p=0.05.

# (a)
# lambda = probability*n=0.05*100
lam = 0.05*100
# We need to find that at least 5 people out of 100 booked will not how up. 
# P(X>=5) = 1 - P(X<=4)
# cumulative probability X >= 5  
1 - poisson.cdf(4,5) # X<=4, lambda = probability*n=0.05*100 = 5
```

(b) If the airline must return the $300 price plus a penalty of $400 to each passenger that cannot get on the flight, what is the expected payout (penalty plus ticket refund) that the airline will pay?

Expected pay = 614.14, calculated in Python:

```python
# (b)
# Airline will pay = 700 for each passenger who showed (when 96th, 97th, .. shows up)
# or when exactly 4,3,2,1,and 0 passengers did not show up:
pay = 1*700* poisson.pmf(4,5) + 2*700* poisson.pmf(3,5) + \
    3*700* poisson.pmf(2,5) + 4*700* poisson.pmf(1,5) + \
    5*700* poisson.pmf(0,5)
pay
```

We can try to answer the following question, what would be the most economical number of tickets to sell to get the maximum expected profitability? 
Here is the link for my [solution](https://github.com/xs-abzal/Blogs_stat_examples/blob/master/Distributions.ipynb).


###**Summary**

Here we applied Poisson distribution to calculate probabilities and expected profit. In the last example, we can further improve our estimations by quantifying the losses caused by allowing overbooking, particularly from losing clients and/or bad reviews because of the overbooking.