python實現--參數估計


求置信區間

抽取樣本, 樣本量為200

np.random.seed(42)

coffee_full = pd.read_csv('coffee_dataset.csv')
coffee_red = coffee_full.sample(200) #this is the only data you might actually get in the real world.
coffee_red.head()

 

 計算樣本中喝咖啡的均值

(coffee_red[coffee_red['drinks_coffee'] == True]['height'].mean()>68.11962990858618

重復抽取樣本,計算其他樣本中喝咖啡的均值,得到抽樣分布

boot_means = []
for _ in range(10000):
    bootsample = coffee_full.sample(200, replace=True)
    mean = bootsample[bootsample['drinks_coffee'] == False]['height'].mean()
    boot_means.append(mean)

抽樣分布

 

 計算抽樣分布的置信區間以估計總體均值, 置信度95%

np.percentile(boot_means, 2.5), np.percentile(boot_means, 97.5)

輸出:

(65.7156685999191, 67.17367777514218)

 

 

轉自:https://blog.csdn.net/Radio_M/article/details/103754184


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM