誤差的分佈
幾乎沒有任何真實世界的流程可以被完美預測。理想的情況是誤差呈常態分佈。這表示有些實際值會高於你的預測,有些會低於你的預測。也就是說,誤差(亦即實際值與預測值的差)會看起來隨機地在 0 附近「漂浮」。
在這個練習中,你會分析一個預先建立的線性模型對警察薪資的預測結果。接著你會檢視誤差,看看它是否近似常態分佈。預測值是一個儲存在 preds 的清單,實際薪資則是一個儲存在 salaries 的清單。
本練習屬於課程
Python 推論基礎
練習說明
- 將誤差計算為實際薪資減去預測薪資。
- 以長條圖繪製誤差。
- 對誤差執行 Anderson–Darling 常態性檢定。
- 找出並列印會拒絕虛無假設的
significance_level(顯著水準)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the error as actual minus predicted salary
error = ____
# Plot the errors as a histogram
plt.____(____)
plt.show()
# Conduct an Anderson-Darling test using the years of experience
result = ____(____)
# Find where the result is significant
print(result.____[result.____ > result.____])