Python验证中心极限定理

29 篇文章 4 订阅
文章通过Python代码展示了中心极限定理的应用,即随着样本数量增加,样本均值的分布逐渐趋向正态分布。在模拟抽样过程中,当样本大小达到一定数量(如30以上),样本均值的分布接近正态曲线,这证实了中心极限定理的有效性。
摘要由CSDN通过智能技术生成

中心极限定理

中心极限定理提出了:无论总体服从什么分布,只要n充分大,那么样本均值分布就接近正态分布。

样本的数量越大,取样次数越多,样本平均值的分布也就越接近于一条正态分布曲线。普遍的经验是,样本的数量必须超过30,中心极限定理才能成立。

中心极限定理有两个要点:

  • 样本的平均值与总体的平均值类似;
  • 样本的平均值呈现正态分布。在这里插入图片描述
Python 代码验证
import numpy.random as np
import seaborn as sns
import matplotlib.pyplot as plt


population_size = 1000000 #总体数量
population = np.rand(1000000) 

#查看总体情况
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
sns.distplot(population,bins=int(180/5),hist = True,kde = False)
plt.title('Histogram of population ',fontsize=20)
plt.xlabel('population',fontsize=20)
plt.ylabel('Count',fontsize=20)
  • 总体分布情况
    在这里插入图片描述
number_of_samples = 10000 #抽样次数
sample_means = np.rand(number_of_samples ) #随机初始化样本均值
sample_size = 2 #样本量n

#抽样
c = np.rand(number_of_samples)  
for i in range(0,number_of_samples):  #运行10000次循环抽样
 c = np.randint(1,population_size,sample_size)   #随机抽取1-population_size之间的整数
 sample_means[i] = population[c].mean()  #计算样本均值并储存到 sample_mean中

#画图
plt.subplot(1,2,1)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
sns.distplot(sample_means,bins=int(180/5),hist = True,kde = False)
plt.title('Histogram of Sample mean',fontsize=20)
plt.xlabel('Sample mean',fontsize=20)
plt.ylabel('Count',fontsize=20)
plt.subplot(1,2,2)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
sns.distplot(sample_means,hist = False,kde = True)
plt.title('Density of Sample mean',fontsize=20)
plt.xlabel('Sample mean',fontsize=20)
plt.ylabel('Density',fontsize=20)
plt.subplots_adjust(bottom=0.1, right=2, top=0.9)
  • Sample Size =1
    在这里插入图片描述

-Sample size =2
在这里插入图片描述

  • Sample size =30在这里插入图片描述

百度百科:中心极限定理
MBA智库:中心极限定理
Verifying Central Limit Theorem using Python

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值