加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

小马哥课堂-统计学-大数定理

发布时间:2020-12-14 03:50:59 所属栏目:大数据 来源:网络整理
导读:Law of large numbers(大数定理) the law of large numbers (LLN) is a theorem that describes the result of performing the same experiment a large number of times. According to the law,the average of the results obtained from a large number of

Law of large numbers(大数定理)

the law of large numbers (LLN) is a theorem that describes the result of performing the same experiment a large number of times. According to the law,the average of the results obtained from a large number of trials should be close to the expected value,and will tend to become closer as more trials are performed.

当试验次数足够大时,样本均值趋向于总体均值。

实例

以掷骰子为例,已知总体均值为3.5,随着实验次数的增加,样本均值将发生怎样的变化呢?

#!/usr/bin/env python3                          
#-*- coding:utf-8 -*-
#############################################
#File Name: lln.py
#Brief: 以掷骰子为例,演示随着试验次数的增加,样本均值趋于总体均值
#Author: frank
#Email: [email?protected]
#Created Time:2018-08-07 22:29:00
#Blog: http://www.cnblogs.com/black-mamba
#Github: https://github.com/suonikeyinsuxiao
#############################################
import numpy as np
import matplotlib.pyplot as plt

#总实验次数
total_num = 1000
#骰子的6面
num_sides = 6

plt.figure(1)

#设置x轴的范围
xmin,xmax = plt.xlim(0,total_num)
print("xmin:{},xmax:{}".format(xmin,xmax))

#设置y轴的范围
ymin,ymax = plt.ylim(1,6)
print("ymin:{},ymax:{}".format(ymin,ymax))

#设置坐标轴的名称
plt.xlabel(‘number of trials‘)
plt.ylabel(‘average‘)



#画均值线
plt.plot((0,total_num),(3.5,3.5),c=‘b‘)

l = []
n_s = range(1,total_num)

#number of trials:n,mean of sample:average
for n in  n_s:
    average = np.mean(np.random.randint(1,7,n))
    l.append(average)
    #print("n:{},average:{}".format(n,average))
    #plt.scatter(n,average,c=‘r‘,s=1,alpha=0.5) 

plt.plot(n_s,l,alpha=0.5,c=‘red‘)


plt.figure(2)
#设置x轴的范围
ymin,ymax = plt.ylim(0,total_num)
print("ymin:{},ymax))
#设置y轴的范围
xmin,xmax = plt.xlim(1,6)
print("xmin:{},xmax))

#设置坐标轴的名称
plt.xlabel(‘number of trials‘)
plt.ylabel(‘average‘)

plt.plot((3.5,(0,c=‘b‘)

#plt.plot(l,n_s,c=‘red‘)
for n in  n_s:
    average = np.mean(np.random.randint(1,average))
    plt.scatter(average,n,alpha=0.5) 

plt.show()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读