统计机器学习-泊松分布

泊松分布:

模型:假设单位时间内发生时间 λ \lambda λ次,求单位时间内事件发生x次的概率。
分布函数:
p ( x ) = e − λ λ x x ! p(x)=\frac{e^{-\lambda}\lambda^x}{x!} p(x)=x!eλλx
矩母函数:
M x ( t ) = E ( e t x ) = ∑ x = 0 ∞ e t x e − λ λ x x ! M_x(t)=E(e^{tx})=\sum_{x=0}^∞ \frac{e^{tx}e^{-\lambda}\lambda^x}{x!} Mx(t)=E(etx)=x=0x!etxeλλx
期 望 E ( x ) = λ   ;   方 差 V a r ( x ) = λ 期望E(x)=\lambda \ ;\ 方差Var(x)=\lambda E(x)=λ  Var(x)=λ
似然函数:
L = − n λ + ∑ i = 1 n ( x i l n λ − l n x i ) L=-n\lambda+\sum_{i=1}^n(x_iln\lambda-lnx_i) L=nλ+i=1n(xilnλlnxi)
性质:
x 1 ∼ P o i s s o n ( λ 1 )   , x 2 ∼ P o i s s o n ( λ 2 ) x_1\sim Poisson(\lambda_1) \ ,x_2\sim Poisson(\lambda_2) x1Poisson(λ1) x2Poisson(λ2)
x 1 + x 2 ∼ P o i s s o n ( λ 1 + λ 2 ) x_1+x_2\sim Poisson(\lambda_1+\lambda_2) x1+x2Poisson(λ1+λ2)


用matplotlib验证这一性质:

import numpy as np
import matplotlib.pyplot as plt

plt.xlim(0,30)
plt.ylim(0.00,0.20)
sample1 = np.random.poisson(lam=5, size=10000) 
sample2 = np.random.poisson(lam=10, size=10000) 
sample3 = np.random.poisson(lam=15, size=10000)
pillar=30
s1=plt.hist(sample1,rwidth=0.9,alpha=0.6,density=True,label="x1",bins=pillar,range=[0,pillar])
plt.plot(s1[1][0:pillar],s1[0],'blue')
s2=plt.hist(sample2,rwidth=0.9,alpha=0.6,density=True,label="x2",bins=pillar,range=[0,pillar])
plt.plot(s2[1][0:pillar],s2[0],'orange')
s3=plt.hist(sample3,rwidth=0.9,alpha=0.6,density=True,label="x3",bins=pillar,range=[0,pillar])
plt.plot(s3[1][0:pillar],s3[0],'g')
s4=plt.hist(sample1+sample2,rwidth=0.9,alpha=0.6,density=True,label="x3=x1+x2",bins=pillar,range=[0,pillar])
plt.plot(s4[1][0:pillar],s4[0],'r')
plt.legend()
plt.show()

在这里插入图片描述
泊松分布与二项分布的关系:

二项分布:
C n x p x ( 1 − p ) n − x C_n^x p^x(1-p)^{n-x} Cnxpx(1p)nx
二者关系:
lim ⁡ n → ∞ ( x n ) p x ( 1 − p ) n − x = e − λ λ x x ! \lim_{n\to∞}\big(_x^n\big)p^x(1-p)^{n-x}=\frac{e^{-\lambda }\lambda^x}{x!} nlim(xn)px(1p)nx=x!eλλx
证明:
令 p = λ n 令p=\frac{\lambda}{n} p=nλ
lim ⁡ n → ∞ ( x n ) ( λ n ) x ( 1 − λ n ) n − x \lim_{n\to∞}\big(_x^n\big)(\frac{\lambda}{n})^x(1-\frac{\lambda}{n})^{n-x} nlim(xn)(nλ)x(1nλ)nx
= lim ⁡ n → ∞ n ! x ! ( n − x ) ! ( λ n ) x ( 1 − λ n ) n − x =\lim_{n\to∞}\frac{n!}{x!(n-x)!}(\frac{\lambda}{n})^x(1-\frac{\lambda}{n})^{n-x} =nlimx!(nx)!n!(nλ)x(1nλ)nx
= λ x x ! lim ⁡ n → ∞ n ! x ! ( n − x ) ! ( 1 − λ n ) n ( 1 − λ n ) n − x =\frac{\lambda^x}{x!} \lim_{n\to∞}\frac{n!}{x!(n-x)!}(1-\frac{\lambda}{n})^n(1-\frac{\lambda}{n})^{n-x} =x!λxnlimx!(nx)!n!(1nλ)n(1nλ)nx

在这里插入图片描述
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt


def draw(n,p,lam):
    plt.title("n={}, p={}, $\lambda$={}".format(n,p,lam))
    b = np.random.binomial(n=n,p=p, size=1000)
    p = np.random.poisson(lam=lam, size=1000) 
    pillar=50
    sb=plt.hist(b,rwidth=0.9,alpha=0.6,density=True,bins=pillar,range=[0,pillar],label="binomial")
    plt.plot(sb[1][0:pillar],sb[0],'blue')
    sp=plt.hist(p,rwidth=0.9,alpha=0.6,density=True,bins=pillar,range=[0,pillar],label="poisson")
    plt.plot(sp[1][0:pillar],sp[0],'orange')
    plt.legend()


plt.figure(figsize=(8,8),dpi=80)

plt.subplot(221)
draw(100,0.1,10)

plt.subplot(222)
draw(100,0.1,20)

plt.subplot(223)
draw(300,0.1,10)

plt.subplot(224)
draw(10,0.1,50)

plt.show()

(n×p越接近于 λ \lambda λ,拟合程度越好)
在这里插入图片描述

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值