欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

参数估计(python实现)

程序员文章站 2022-05-09 10:56:44
...

求置信区间

抽取样本, 样本量为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()

参数估计(python实现)
计算样本中喝咖啡的均值

(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)

抽样分布
参数估计(python实现)
计算抽样分布的置信区间以估计总体均值, 置信度95%

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

输出:

(65.7156685999191, 67.17367777514218)
相关标签: 统计学