測試樣本大小
為了進行假設檢定並確保結果公正,樣本必須符合三個條件:來自母體的隨機抽樣、觀測值彼此獨立,以及觀測值的數量足夠。這三者之中,只有最後一項可以較容易用程式碼檢查。
最小樣本大小取決於你要執行的假設檢定種類。現在你將在 late_shipments 資料集上測試幾種情境。
請注意,pandas 的 .all() 方法可用來檢查所有元素是否皆為 true。舉例來說,給定一個數值內容的 DataFrame df,你可以用 (df < 5).all() 來檢查所有元素是否都小於 5。
late_shipments 已可使用,且已將 pandas 載入為 pd。
本練習屬於課程
Python 中的假設檢定
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Count the freight_cost_group values
counts = ____
# Print the result
print(counts)
# Inspect whether the counts are big enough
print((counts >= ____).all())