最大化似然(第 1 部分)
之前,我们选择样本的 mean 作为总体模型参数 mu 的估计值。但我们如何知道样本均值是最优估计量呢?这个问题不太简单,所以我们分两步来做。
在第 1 部分,您将用计算的方法来求取给定估计值的对数似然。接着在第 2 部分,我们会看到:当您对许多可能的估计值计算对数似然时,会有一个猜测使似然达到最大。

本练习是课程的一部分
Python 线性建模入门
练习说明
- 计算预加载的
sample_distances的mean()和std(),作为概率模型参数的猜测值。 - 使用由
sample_mean和sample_stdev构建的gaussian_model(),为每个distance计算概率。 - 计算
loglikelihood,其等于概率probs的log()的sum()。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute sample mean and stdev, for use as model parameter value guesses
mu_guess = np.____(sample_distances)
sigma_guess = np.____(sample_distances)
# For each sample distance, compute the probability modeled by the parameter guesses
probs = np.zeros(len(sample_distances))
for n, distance in enumerate(sample_distances):
probs[n] = gaussian_model(____, mu=____, sigma=____)
# Compute and print the log-likelihood as the sum() of the log() of the probabilities
loglikelihood = np.____(np.____(probs))
print('For guesses mu={:0.2f} and sigma={:0.2f}, the loglikelihood={:0.2f}'.format(mu_guess, sigma_guess, ____))