# Simulate MLE for Poisson distribution [closed]

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
plots.style.use('fivethirtyeight')

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

#log-likelihood
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:
print(lam)
ls = np.append(ls, np.exp(l(lam)))

plots.plot(lams,ls)


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

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