最大化概似,第 1 部分
先前我們選擇樣本的 mean 作為母體模型參數 mu 的估計值。但我們怎麼知道樣本平均數是最好的估計量呢?這不太直觀,所以我們分成兩步來做。
在第 1 部分,你會用計算的方法來求出某個估計值的對數概似。接著在第 2 部分,我們會看到:當你對許多可能的估計值計算對數概似時,會有一個估計使得概似達到最大。

本練習屬於課程
Python 線性建模入門
練習說明
- 先對已預先載入的
sample_distances計算mean()和std(),作為機率模型參數的猜測值。 - 使用由
sample_mean與sample_stdev建立的gaussian_model(),為每個distance計算機率。 - 將機率
probs取log()後sum(),得到loglikelihood。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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, ____))