常態性檢定

Python 推論基礎

Paul Savala

Assistant Professor of Mathematics

美國男性身高

一個近似常態分佈的直方圖,平均身高為 180 公分,最小 160 公分,最大 200 公分。

Python 推論基礎

模型殘差

散佈圖:x 軸為任職年數,y 軸為年薪,呈整體正向線性趨勢。資料上疊有一條紅色的最佳擬合線。

預測線上、下的殘差應大致各半

Python 推論基礎

模型殘差

直方圖:x 軸為「residual (error)」;y 軸為「count」;呈雙峰分佈,一峰約在負的一萬,另一峰約在正的三萬。

Python 推論基礎

常態分佈的應用

  • 參數檢定-假設常態性的假設檢定
  • T 檢定比較平均數:
    • 假設樣本平均數呈常態分佈
    • 若不成立,結論不可靠
Python 推論基礎

直方圖:x 軸為 60,000 到 95,000 的薪資,y 軸為頻率。直方圖大致接近常態。

Python 推論基礎

Anderson–Darling 常態性檢定

  • 檢驗常態性假設

$H_0$:資料呈常態分佈

$H_a$:資料「不」呈常態分佈

Python 推論基礎

SciPy 中的 Anderson–Darling 檢定

result = stats.anderson(police_df['Annual Salary'])

result.statistic
27.41
result.critical_values
[0.574, 0.654, 0.784, 0.915, 1.088]
result.significance_level[result.statistic > result.critical_values]
[15.  10.   5.   2.5  1. ]
Python 推論基礎

配適常態分佈

mu, std = stats.norm.fit(police_df['Annual Salary'])

estimated_pct_under_70k = stats.norm.cdf(70000, loc=mu, scale=std)
print(estimated_pct_under_70k)
0.27
actual_under_70k = police_df[police_df['Annual Salary'] < 70000]

print(len(actual_under_70k) / len(police_df))
0.20
Python 推論基礎

一起來練習吧!

Python 推論基礎

Preparing Video For Download...