模型不確定性與樣本分佈

Python 線性建模入門

Jason Vestuto

Data Scientist

母體不可得

日數對溫度區間的長條圖,8 月每日最高溫

Python 線性建模入門

以樣本作為母體模型

2 個長條圖:一個為樣本、一個為母體,皆為標準化日數對溫度區間;樣本各區間高度與母體相近

Python 線性建模入門

樣本統計量

單一樣本的長條圖,日數對溫度區間

Python 線性建模入門

自助法重抽樣(Bootstrap)

3 個長條圖,各代表 3 個樣本;各自中心略有偏移,座標為日數對溫度區間

Python 線性建模入門

重抽樣分佈

平均值的長條圖,座標為樣本數對平均溫度區間

Python 線性建模入門

以程式實作 Bootstrap

# Use sample as model for population
population_model = august_daily_highs_for_2017
# Simulate repeated data acquisitions by resampling the "model"
for nr in range(num_resamples):
    bootstrap_sample = np.random.choice(population_model, size=resample_size, replace=True)
    bootstrap_means[nr] = np.mean(bootstrap_sample)
# Compute the mean of the bootstrap resample distribution
estimate_temperature = np.mean(bootstrap_means)
# Compute standard deviation of the bootstrap resample distribution
estimate_uncertainty = np.std(bootstrap_means)
Python 線性建模入門

放回抽樣

# Define the sample of notes
sample = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
# Replace = True, repeats are allowed
bootstrap_sample = np.random.choice(sample, size=4, replace=True)
print(bootstrap_sample)
C C F G
Python 線性建模入門

放回抽樣

# Replace = False
bootstrap_sample = np.random.choice(sample, size=4, replace=False)
print(bootstrap_sample)
C G A F
# Replace = True, more lengths are allowed
bootstrap_sample = np.random.choice(sample, size=16, replace=True)
print(bootstrap_sample)
C C F G C G A E F D G B B A E C
Python 線性建模入門

一起來練習吧!

Python 線性建模入門

Preparing Video For Download...