點估計的相對誤差

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...