開始使用免費開始

評估 ldl 變數的分配配適度

在這個練習中,你將聚焦於糖尿病資料集 dia 的單一變數:ldl 血清值。你會根據 Kolmogorov–Smirnov 檢定提供的額外資訊,判斷常態分配是否仍是 ldl 的好選擇。

dia DataFrame 已為你載入。以下函式庫也已匯入:pandas 作為 pdnumpy 作為 np,以及 scipy.stats 作為 st

本練習屬於課程

Python 的 Monte Carlo 模擬

檢視課程

練習說明

  • 定義一個名為 list_of_dists 的清單,依序包含候選分配:Laplace、normal 與 exponential;請使用 scipy.stats 中正確的名稱。
  • 在迴圈中,使用對應的機率分配來配適資料,並存為 param
  • 執行 Kolmogorov–Smirnov 檢定以評估配適良好度,結果存為 result

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# List candidate distributions to evaluate
list_of_dists = [____]
for i in list_of_dists:
    dist = getattr(st, i)
    # Fit the data to the probability distribution
    param = dist.____
    # Perform the ks test to evaluate goodness-of-fit
    result = ____
    print(result)
編輯並執行程式碼