点估计的相对误差

Python 抽样

James Chapman

Curriculum Manager, DataCamp

样本量即行数

len(coffee_ratings.sample(n=300))
300
len(coffee_ratings.sample(frac=0.25))
334
Python 抽样

不同样本量

coffee_ratings['total_cup_points'].mean()
82.15120328849028
coffee_ratings.sample(n=10)['total_cup_points'].mean()
83.027
coffee_ratings.sample(n=100)['total_cup_points'].mean()
82.4897
coffee_ratings.sample(n=1000)['total_cup_points'].mean()
82.1186
Python 抽样

相对误差

总体参数:

population_mean = coffee_ratings['total_cup_points'].mean()

点估计:

sample_mean = coffee_ratings.sample(n=sample_size)['total_cup_points'].mean()

相对误差(百分比):

rel_error_pct = 100 * abs(population_mean-sample_mean) / population_mean
Python 抽样

相对误差 vs. 样本量

import matplotlib.pyplot as plt
errors.plot(x="sample_size", 
            y="relative_error", 
            kind="line")
plt.show()

特性:

  • 噪声大,尤其在小样本下
  • 幅度先陡后缓
  • 样本量等于总体时,相对误差降为 0

相对误差与样本量的折线图。

Python 抽样

开始练习!

Python 抽样

Preparing Video For Download...