nk_science
nk_science

Reputation: 23

Scipy: poisson fit not working on particular data set

I wrote a script to fit poisson distribution which seems to work well with a data set generated using python's random.poisson but it does't work on the data set I need to fit. Script is:

In [6]: from scipy.misc import factorial

In [7]: from scipy.optimize import curve_fit

In [8]: import numpy as np

In [9]: import matplotlib.pyplot as plt


In [11]: def poisson(k, lambd):
   ....:     print(lambd)
   ....:     return(lambd**k/factorial(k))*np.exp(-lambd)

Data is :

In [12]: x = [ 0.0036533, 0.00972361, 0.01579392, 0.02186422, 0.02793453, 0.03400484, 0.04007515, 0.04614546, 0.05221577, 0.05828608, 0.06435639, 0.0704267, 0.07649701, 0.08256731, 0.08863762]

In [13]: y =[ 0.64005518, 0.10825634, 0.05954099, 0.04330254, 0.03383011, 0.02165127, 0.02435768, 0.01623845, 0.01082563, 0.00676602, 0.00947243, 0.00947243, 0.00270641, 0.00405961, 0.00947243]

In [18]: popt, pcov = curve_fit(poisson, x, y)

So the problem is that best value of lambd found by this scipt(=2.82) is much higher than it should be. Can someone help please? Thanks in advance

Upvotes: 1

Views: 2284

Answers (1)

Ffisegydd
Ffisegydd

Reputation: 53698

The Poisson distribution is a discrete probability distribution. As such it is not appropriate for non-discrete (i.e. non-integer) numbers in your x variables array.

The reason that it works for random data provided via random.poisson is that this data will be discrete, not continuous.

You should pick an alternative distribution that is continuous.

Upvotes: 2

Related Questions