平均中的平均
你想知道每筆交易的使用者數(num_users)平均是多少,而且希望用整家公司層級的數字,這樣就能判斷 Amir 的交易使用者數是高於還是低於公司的平均值。問題在於,過去一年公司處理了超過一萬筆交易,要彙整所有資料並不切實際。因此,你將透過對交易進行多次隨機抽樣來估計平均數,因為這比向公司所有人收集資料容易得多。
amir_deals 已可使用,公司的所有交易使用者資料在 all_deals。pandas 已以 pd 載入,numpy 也已以 np 載入。
本練習屬於課程
Python 統計學入門
練習說明
- 將隨機種子設為
321。 - 從
all_deals['num_users']以放回抽樣的方式抽取 30 次、每次大小為 20 的樣本,並計算每個樣本的平均數。把這些樣本平均數儲存在sample_means。 - 列印
sample_means的平均數。 - 列印
amir_deals資料表中num_users欄位的平均數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Set seed to 321
____
sample_means = []
# Loop 30 times to take 30 means
for i in range(____):
# Take sample of size 20 from num_users col of all_deals with replacement
cur_sample = ____
# Take mean of cur_sample
cur_mean = ____
# Append cur_mean to sample_means
sample_means.append(____)
# Print mean of sample_means
print(____)
# Print mean of num_users in amir_deals
print(____)