便利抽样

Python 抽样

James Chapman

Curriculum Manager, DataCamp

《The Literary Digest》的选举预测

1936 年《The Literary Digest》头版,标题为选举预测。预计兰登获 130 万票,罗斯福略低于 100 万票。

  • 预测:兰登 57%;罗斯福 43%
  • 实际:兰登 38%;罗斯福 62%
  • 样本不代表总体,导致样本偏差
  • 以最省事方式收集数据称为便利抽样
Python 抽样

估计法国人的平均年龄

巴黎迪士尼乐园的照片。

  • 在巴黎迪士尼抽样调查 10 人
  • 平均年龄 24.6 岁
  • 这能很好估计全法吗?
1 图片作者: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...