开始使用免费开始使用

最大化似然(第 1 部分)

之前,我们选择样本的 mean 作为总体模型参数 mu 的估计值。但我们如何知道样本均值是最优估计量呢?这个问题不太简单,所以我们分两步来做。

在第 1 部分,您将用计算的方法来求取给定估计值的对数似然。接着在第 2 部分,我们会看到:当您对许多可能的估计值计算对数似然时,会有一个猜测使似然达到最大。

本练习是课程的一部分

Python 线性建模入门

查看课程

练习说明

  • 计算预加载的 sample_distancesmean()std(),作为概率模型参数的猜测值。
  • 使用由 sample_meansample_stdev 构建的 gaussian_model(),为每个 distance 计算概率。
  • 计算 loglikelihood,其等于概率 probslog()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, ____))
编辑并运行代码