嘗試其他候選機率分配
正確選擇輸入的機率分配是進行 Monte Carlo 模擬的關鍵。影片中,我們評估了三種分配,以判斷哪一種最適合 age 變數:Laplace、常態,以及指數分配。結果顯示常態分配最適合。
在這個練習中,你要看看能否找到比常態分配更好的擬合!你會評估均勻、常態,以及指數分配的擬合表現。糖尿病資料集已載入為 DataFrame dia。常態分配還會是最佳選擇嗎?
以下函式庫已為你匯入:pandas 作為 pd、scipy.stats 作為 st,以及 numpy 作為 np。
本練習屬於課程
Python 的 Monte Carlo 模擬
練習說明
- 使用
.fit()對age資料配適分配;接著使用.nnlf()取得此配適的最大概似估計(MLE)值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
distributions = [st.uniform, st.norm, st.expon]
mles = []
for distribution in distributions:
# Fit the distribution and obtain the MLE value
pars = distribution.____
mle = distribution.____
mles.append(mle)
print(mles)