便利抽樣

Python 中的抽樣

James Chapman

Curriculum Manager, DataCamp

《Literary Digest》的選舉預測

1936 年《Literary Digest》的頭版,標題為選舉預測。預測 Landon 得 130 萬票,Roosevelt 略低於 100 萬票。

  • 預測:Landon 57%;Roosevelt 43%
  • 實際:Landon 38%;Roosevelt 62%
  • 樣本不具代表性,導致「樣本偏誤」
  • 以最省力的方法蒐集資料,稱為「便利抽樣」
Python 中的抽樣

估計法國人的平均年齡

巴黎迪士尼樂園的照片。

  • 在巴黎迪士尼隨機調查 10 人
  • 平均年齡 24.6 歲
  • 這能代表全法國的估計嗎?
1 Image by Sean MacEntee
Python 中的抽樣

這份調查的準確度如何?

年份 法國平均年齡
1975 31.6
1985 33.6
1995 36.2
2005 38.9
2015 41.2
  • 24.6 歲是很差的估計
  • 會去迪士尼的人不代表整體人口
Python 中的抽樣

便利抽樣下的咖啡評分

coffee_ratings["total_cup_points"].mean()
82.15120328849028
coffee_ratings_first10 = coffee_ratings.head(10)
coffee_ratings_first10["total_cup_points"].mean()
89.1
Python 中的抽樣

視覺化選擇偏誤

import matplotlib.pyplot as plt
import numpy as np
coffee_ratings["total_cup_points"].hist(bins=np.arange(59, 93, 2))
plt.show()

 

coffee_ratings_first10["total_cup_points"].hist(bins=np.arange(59, 93, 2))
plt.show()
Python 中的抽樣

母體與便利樣本的分佈

母體: 母體杯測分數的長條圖。

便利樣本: 樣本杯測分數的長條圖。

Python 中的抽樣

隨機樣本的選擇偏誤視覺化

coffee_sample = coffee_ratings.sample(n=10)
coffee_sample["total_cup_points"].hist(bins=np.arange(59, 93, 2))
plt.show()
Python 中的抽樣

母體與簡單隨機樣本的分佈

母體: 母體杯測分數的長條圖。

隨機樣本: 隨機樣本杯測分數的長條圖。

Python 中的抽樣

一起來練習吧!

Python 中的抽樣

Preparing Video For Download...