Subscribe to DSC Newsletter

Solving Poisson Distribution Problems Using SciPy

Imagine the following business problem:

A call center has a rule that if more than 8 customers calls in 24 hours about Issue X, then there should be an alarm & that that Issue X should be forwarded to Tier 2 team for further investigation. However, the Tier 2 team believes that 24 hours is too long to wait since the customer experience could suffer. They want to predict BEFORE the 24 hour interval. Therefore, they want the probability at any given time based on historical hourly calling pattern if the 8 customers calling in 24 hours will be breached?

Enter the Poisson distribution. From Wikipedia.

The Poisson distribution can be applied to systems with a large number of possible events, each of which is rare. How many such events will occur during a fixed time interval? Under the right circumstances, this is a random number with a Poisson distribution.

Poisson Distribution Definition

A discrete random variable X  is said to have a Poisson distribution with parameter λ > 0, if, for k = 0, 1, 2, …, the probability mass function of X  is given by:

where

  • e is Euler's number (e = 2.71828...)
  • k! is the factorial of k.

The positive real number λ is equal to the expected value of X and also to its variance[7]

Scipy is a python library that is used for Analytics,Scientific Computing and Technical Computing. Using stats.poisson module we can easily compute poisson distribution of a specific problem

To calculate poisson distribution we need two variables

  1. Poisson random variable (x): Poisson Random Variable is equal to the overall REMAINING LIMIT that needs to be reached
  2. Assume that when the alarm limit is 8 and within the two hours, you get 2 calls, the remaining limit it =6 and the Poisson random variable = 6
  3. Average rate of success(rate_of_success): average rate of success for one hour avg_suss_one_hour=8 calls/24 periods = .32
  1. We need to calculate average rate of success for remaining hours that is 24-2=22
  2. Average rate of success for remaining(22) hours= avg_suss_one_hour*22
  3. Rate_of_success=avg_suss_rm_hours=0.32*22=7.14

The formula for poisson distribution using scipy module:

Proabability_reached = float(1-scipy.stats.distributions.poisson.cdf(poisson random variable-1, rate_of_success)) * 100

 

Code For Poisson Distribution

import scipy

from scipy.stats import poisson

def poisson_probability(alarmlimit,no_of_calls,current_time):

       hourly_rate = float(alarmlimit)/24.0

       remain_hours = 24 - int(current_time)    

       rate_of_success = float(remain_hours * hourly_rate)

       if alarmlimit > no_of_calls and remain_hours!=0:

           """poisson variable is remaining no of calls to reach the limit"""

           poisson_variable = alarmlimit - no_of_calls

           probability_remain = float(scipy.stats.distributions.poisson.pmf(poisson_variable, rate_of_success))*100

           probability_reached = float(1-scipy.stats.distributions.poisson.cdf(poisson_variable-1, rate_of_success)) * 100

       elif alarmlimit > no_of_calls and remain_hours==0:    

            poisson_variable = alarmlimit - no_of_calls

            probability_remain = 0

            probability_reached = 0

       else:

           poisson_variable = 0

           probability_reached = 100

       return (poisson_variable,hourly_rate,remain_hours,probability_reached, rate_of_success)

if __name__=="__main__":

   alarmlimit=8

   no_of_calls=2

   current_time=2#its hours

   poisson_variable,hourly_rate,remain_hours,probability_reached,rate_of_success = poisson_probaility(alarmlimit,no_of_calls,current_time)

   print "poisson Variable x is %d"%(poisson_variable)

   print "Rate of Success in hour %f"%(hourly_rate)

   print "Rate of Success %f"%(rate_of_success)

   print "Remaining hours %d"%(remain_hours)

   print "Probability Reached %f"%(probability_reached)

output from program:

  • Poisson Variable x is 6
  • Rate of Success in hour 0.333333
  • Rate of Success 7.333333
  • Remaining hours 22
  • Probability Reached 73.982648

We can check the Poisson distribution values with an online calculator  

24 Hour Limit

1 Hour Rate

# of Calls

Study Period (in hours)

Remaining Periods

Poisson Variable (X)

Rate of Success

Probability that limit will be breached (%)

8

0.33

2

2

22

6

7.33

74

9

0.375

4

4

20

5

7.50

87

6

0.25

3

5

19

3

4.75

85

12

0.50

8

3

21

4

10.50

99

7

0.29

1

1

23

6

6.70

66

15

0.625

3

6

18

12

11.25

45

Views: 5830

Comment

You need to be a member of Data Science Central to add comments!

Join Data Science Central

Follow Us

Videos

  • Add Videos
  • View All

Resources

© 2017   Data Science Central   Powered by

Badges  |  Report an Issue  |  Privacy Policy  |  Terms of Service