# 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

## closed as off-topic by Hong Ooi, Peter Flom♦Oct 8 '18 at 11:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Hong Ooi, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

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