4/14
Part 2 of 7 · Maximum likelihood estimatesLearn and do

For a normal, maximum likelihood gives the sample mean, and a variance with a catch

The same recipe works for any model with a density. Delivery times look normal, and a normal's log-likelihood is a sum over the days of a term that depends on the mean and the variance. Here's a search over the variance, with the mean at the sample mean:

# 8 delivery times, in days
days = rng.normal(4.0, 1.2, 8).round(1)


def normal_log_likelihood(mu, var, xs):
    return np.sum(-0.5 * np.log(2 * np.pi * var) - (xs - mu) ** 2 / (2 * var))


# 0.0001 to 5
variances = np.arange(1, 50_001) / 10_000
best = variances[np.argmax([normal_log_likelihood(days.mean(), v, days) for v in variances])]
print(f"best variance {best:.3f}; over n {days.var():.3f}; over n - 1 {days.var(ddof=1):.3f}")
Predict

Which variance makes the 8 delivery times most likely?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

What's the maximum likelihood estimate of the standard deviation?

Pick an answer above to see the rest