尤度の最大化(パート1)
これまで、標本の mean を母集団モデルのパラメータ mu の推定値として選びました。では、その標本平均が最良の推定量であることはどう確かめられるのでしょうか。少し難しいので、2つのパートに分けて進めます。
パート1では、ある推定値に対する対数尤度を計算するために、計算的なアプローチを使います。続くパート2では、多くの推定値候補について対数尤度を計算すると、その中の1つが最大尤度を与えることを確認します。

この演習はコースの一部です
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, ____))