According to the theory given $X_i$ ~ $Pois(\lambda)$ iid, the maximum likelihood must be equal to $\sum_{i=1}^{n} X_i/n$ in this case $5.01$

from scipy.stats import poisson
from datascience import *
import numpy as np

%matplotlib inline
import matplotlib.pyplot as plots

# Poisson r.v.
Pois = Table().with_column('PDF',np.random.poisson(lam=5,size=10000))

def l(lam):
logs = make_array()
for k in Pois.column(0):
    logs = np.log(poisson.pmf(k=k,mu = lam))
return np.sum(logs)

# lambdas
lams = np.arange(3,7,0.1)

# likelihood
ls = make_array()
for lam in lams:
  ls = np.append(ls, np.exp(l(lam)))


However, according to the plot the MLE is approximately when lambda = 3


1 Answer 1


That's what I get from your code

I got this plot, which looks pretty good, $\lambda _{mle} \approx5 \approx \lambda$

  • $\begingroup$ Did you use the same code? $\endgroup$
    – user13
    Oct 8, 2018 at 7:31
  • $\begingroup$ yap! on python 3.7... though I needed to install the datascience package, never heard of it before. Oh and I remove the Pois.hist(), since it resulted in an error $\endgroup$
    – Cherny
    Oct 8, 2018 at 7:33
  • $\begingroup$ Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay. $\endgroup$
    – user13
    Oct 8, 2018 at 7:43
  • $\begingroup$ BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16 $\endgroup$
    – user13
    Oct 8, 2018 at 7:47
  • $\begingroup$ Not sure about the exponential decay, but maybe you looked at the distribution of the inverse? I don't want to confuse you too much but you can look at the time between events and you'll get exponential distribution, and Thanks! I'll check it out $\endgroup$
    – Cherny
    Oct 8, 2018 at 7:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.