Plotting Log Likelihood It was suggested I ask this here instead of Stack Overflow.
I am trying to plot the negative log likelihood of an exponential distribution. I am not getting how I am supposed to think of it. The equation for negative log likelihood is provided...
$$l(\lambda; x_1, \dots, x_n) = n \ln(\lambda) - \lambda \sum_{j=1}^n x_j$$
I am not getting how I am supposed to plot it when there is only one output. How is this used in relation to gradient descent? Is this function performed multiple times and the rate parameter changes? I have looked online and cannot find anything I can really understand.

You have some numpy vector, x. Take the sum.
S = np.sum(x)

You have the sample size, n, by taking the length of x.
n = len(x) # maybe something related to x.shape

Now evelyate the function over a spectrum of lambda values, such as every $0.1$ from $-5$ to $+5$. I’ll call the variable “lamb” since “lambda” has a meaning in Python.
lamb = np.arange(-5, 5.01, 0.1)
L = n * np.log(lamb) - lamb * S

Plot it!
plt.scatter(x, L)

The likelihood function is just a function of your lambda values.
To find the maximum likelihood estimator of $\lambda$, determine the $\lambda$ that maximizes this function.
SPOILERS BELOW
(Don’t read ahead until you’ve figured out the bug in the above code (or at least have given it an attempt and think you’ve figured it out).)
You can’t take a logarithm of a number unless they it positive, so you would have to define your lamb vector as:
lamb = np.arange(0.1, 5.01, 0.1)

(Yes, complex logarithms exist.)
