python绘制常用的概率分布曲线

推荐阅读:如何理解概率分布函数和概率密度函数

正态分布(Nomal Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
import math
# 均值
u = 0
#标准差 
sig = math.sqrt(0.2)

x = np.linspace(u - 3 * sig, u + 3 * sig, 50)
y_sig = np.exp(-(x - u) ** 2 / (2 * sig ** 2) / (math.sqrt(2 * math.pi) * sig))
plt.plot(x,y_sig,"r-",linewidth=2)
plt.grid(True)
plt.show()

正态分布概率密度函数曲线

两点分布 /伯努利分布(Two Point Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
p = 0.7
x = [0,1]
y = [1-p, p]
plt.scatter(x,y) # 散点图
plt.grid(True)
plt.show()

二项分布 (Binomial Distribution)

二项分布,即重复n次的伯努利试验,用ξ表示随机试验的结果。如果事件发生的概率是p,则不发生的概率q=1-p,N次独立重复试验中发生K次的概率是
P(ξ=K)= C(n,k) * p^k * (1-p)^(n-k),其中C(n, k) =n!/(k!(n-k)!). 那么就说这个属于二项分布。其中P称为成功概率。记作ξ~B(n,p)
期望:Eξ=np;
方差:Dξ=npq, 其中q=1-p

import numpy as np
import matplotlib.pyplot as plt
from scipy.special import comb
p = 0.4
n = 10
x = np.linspace(0,n,n+1)
y = comb(n,x)*p**x*(1-p)**(n-x)
print(x)
print(y)
plt.scatter(x,y)
plt.grid(True)
plt.show()

几何分布 (Geometric Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
p = 0.4
n = 10
x = np.linspace(1,n,n)
y = p*(1-p)**(x-1)
print(x)
print(y)
plt.scatter(x,y)
plt.grid(True)
plt.show()

泊松分布(Possion Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt

x = np.random.poisson(lam = 5, size = 10000)
pillar = 15
a = plt.hist(x, pillar, color = 'g')
plt.plot(a[1][0:pillar], a[0],'r')
plt.grid()
plt.show()

均匀分布 (Uniform Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
a = 3
b = 5
x = np.linspace(a, b, 50)
y = []
for i in range(0,50):
	y.append(1 / (b - a))
plt.plot(x,y,"r-",linewidth=2)
plt.grid(True)
plt.show()

指数分布 (Exponential Distribution)

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt

x = np.random.exponential(scale = 100, size = 10000)
pillar = 25
a = plt.hist(x, pillar, color = 'g')
plt.plot(a[1][0:pillar], a[0],'r')
plt.grid()
plt.show()
  • 8
    点赞
  • 72
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值