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

python实现二项分布、泊松分布和正态分布

程序员文章站 2024-03-25 21:27:28
...
from scipy.stats import binom,poisson,norm
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
fig,ax = plt.subplots(1,1)
n = 100
p = 0.5
mean,var,skew,kurt = binom.stats(n,p,moments='mvsk')
print(mean,var,skew,kurt)
x = np.arange(binom.ppf(0.01, n, p),binom.ppf(0.99, n, p))
ax.plot(x, binom.pmf(x, n, p),'o')
plt.title('二项分布概率质量函数')
plt.show()

python实现二项分布、泊松分布和正态分布

fig,ax = plt.subplots(1,1)
λ = 2
mean,var,skew,kurt = poisson.stats(mu,moments='mvsk')
print (mean,var,skew,kurt)
x = np.arange(poisson.ppf(0.01, λ),poisson.ppf(0.99, λ))
ax.plot(x, poisson.pmf(x, mu),'o')
plt.title('泊松分布概率质量函数')
plt.show()

python实现二项分布、泊松分布和正态分布

fig,ax = plt.subplots(1,1)
mu = 0
std = 1.0
mean,var,skew,kurt = norm.stats(mu,std,moments='mvsk')
print (mean,var,skew,kurt)
x = np.linspace(norm.ppf(0.01,mu,std),norm.ppf(0.99,mu,std),100)
ax.plot(x, norm.pdf(x,mu,std),'b-',label = 'norm')
plt.title('正太分布概率密度函数')
plt.show()

python实现二项分布、泊松分布和正态分布