Skip to content Skip to sidebar Skip to footer

Calculate Poisson Probability Percentage

When you use the POISSON function in Excel (or in OpenOffice Calc), it takes two arguments: an integer an 'average' number and returns a float. In Python (I tried RandomArray and

Solution 1:

scipy has what you want

>>> scipy.stats.distributions
<module 'scipy.stats.distributions'from'/home/coventry/lib/python2.5/site-packages/scipy/stats/distributions.pyc'>
>>> scipy.stats.distributions.poisson.pmf(6, 2.6)
array(0.031867055625524499)

It's worth noting that it's pretty easy to calculate by hand, too.

Solution 2:

It is easy to do by hand, but you can overflow doing it that way. You can do the exponent and factorial in a loop to avoid the overflow:

defpoisson_probability(actual, mean):
    # naive:   math.exp(-mean) * mean**actual / factorial(actual)# iterative, to keep the components from getting too large or small:
    p = math.exp(-mean)
    for i in xrange(actual):
        p *= mean
        p /= i+1return p

Solution 3:

This page explains why you get an array, and the meaning of the numbers in it, at least.

Post a Comment for "Calculate Poisson Probability Percentage"