当前位置:网站首页>Commonly used discrete random distribution
Commonly used discrete random distribution
2022-07-03 11:04:00 【hflag168】
Commonly used discrete random variable distribution and its correlation function
In the third party Library scipy in , It includes the distribution commonly used in Statistics . Mainly in the scipy.stats Module , So before using it , Except to install scipy Outside , Also import the distribution of responses .
One scipy.stats Discrete distribution commonly used in
- Bernoulli distribution (
Bernoulli) - The binomial distribution (
Binomial) - Poisson distribution (
Poisson) - Geometric distribution (
Geometri)
Two Methods common to random variables
- Probability Mass Function(
pmf) Probability mass function , Straight white point , Is to find the probability of taking a given sample point .
p ( x k ) = P ( X = x k ) p(x_k)=P(X=x_k) p(xk)=P(X=xk)
Cumulative Distribution Function(
cdf) Cumulative distribution functionF ( x ) = P ( X ≤ x ) = ∑ x k ≤ x p ( x k ) F(x) = P(X\le x)=\sum_{x_k\le x}p(x_k) F(x)=P(X≤x)=∑xk≤xp(xk)
Survival Function(sf) Survival function
S ( x ) = 1 − F ( x ) = P ( X > k ) S(x)=1-F(x)=P(X>k) S(x)=1−F(x)=P(X>k)
Percent Point Function(
ppf) Percentiles ,ppfyescdfThe inverse function ofInverse survival Function(
isf) Inverse function of survival function .
3、 ... and Python The use of random variable distribution commonly used in
3.1 Freeze a distribution
Each distribution has fixed parameters , If these parameters are transmitted every time when using this distribution , Obviously it's more troublesome . Therefore, you can first pass in the corresponding parameters , That is to freeze this distribution .
>>> from scipy import stats
>>> rv1 = stats.binom(100,0.05) # Freeze one `n=100, p=0.05` The binomial distribution of
>>> rv2 = stats.poisson(5) # Freeze a parameter λ=5 The Poisson distribution of
>>> rv3 = stats. geom(0.5) # Freeze a parameter p=5 The geometric distribution of
3.2 The use of correlation functions
X ∼ B ( 10 , 0.05 ) X\sim B(10,0.05) X∼B(10,0.05) , seek P ( x = 10 ) , P ( x ≤ 10 ) P(x=10), P(x\le10) P(x=10),P(x≤10)
>>> from scipy import stats
>>> rv1 = stats.binom(100, 0.05) # Frozen distribution
>>> rv1.pmf(10) # Find the probability of the given value of random variables
0.016715884095931225
>>> rv1.cdf(10) # Find the cumulative probability
0.9885275899325152
X ∼ P ( 5 ) X\sim P(5) X∼P(5), seek P ( x = 10 ) , P ( x ≤ 10 ) P(x=10), P(x\le 10) P(x=10),P(x≤10)
>>> from scipy import stats
>>> rv2 = stats.poisson(5) # Frozen distribution
>>> rv2.pmf(10)
0.018132788707821854
>>> rv2.cdf(10)
0.9863047314016171
Four Comparison between binomial distribution and Poisson distribution
In binomial distribution , When n It's big , p In small cases , Poisson distribution can be approximately used to calculate .
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
def binomAndpoisson(n, p):
# Frozen distribution
lambda1 = n*p
rv1 = stats.binom(n, p)
rv2 = stats.poisson(lambda1)
x = np.arange(n)
width = .35
pbs=rv1.pmf(x)
pps = rv2.pmf(x)
fig, ax = plt.subplots()
rects1 = ax.bar(x-width/2, pbs, width, label="binom")
rects2 = ax.bar(x+width/2, pps, width, label="poisson")
ax.set_ylabel('Probability')
ax.set_title("Compare binom(n={},p={}) with poisson({} )".format(n,p, n*p))
ax.set_xticks(x)
ax.legend()
# ax.bar_label(rects1, padding=3)
# ax.bar_label(rects2, padding=3)
fig.tight_layout()
plt.show()
binomAndpoisson(5, 0.2)
# binomAndpoisson(50, 0.2)
# binomAndpoisson(100, 0.02)
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-KQHOsgku-1616908810491)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210328124354427.png)]
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-44uVtLRE-1616908810494)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210328130858423.png)]
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-B7oDscno-1616908810496)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210328131430125.png)]
It can be seen from the test on the summary , When the binomial distribution is n It's big , p Very hour , It can be used λ = n p \lambda=np λ=np To approximate the Poisson distribution of .
908810494)]
[ Outside the chain picture transfer in …(img-B7oDscno-1616908810496)]
It can be seen from the test on the summary , When the binomial distribution is n It's big , p Very hour , It can be used λ = n p \lambda=np λ=np To approximate the Poisson distribution of .
Welcome to visit Python And probability courses :https://www.bilibili.com/video/BV1sh411Q7mz
边栏推荐
- How to make a blood bar in the game
- 硬 货 | 一改测试步骤代码就全写?为什么不试试用 Yaml实现数据驱动?
- Qt:qss custom qradiobutton instance
- "Core values of testing" and "super complete learning guide for 0 basic software testing" summarized by test engineers for 8 years
- Basic usage of sqlmap
- 现在零基础转行软件测试还OK吗?
- 字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?
- “测试人”,有哪些厉害之处?
- 测试理论概述
- 文件上传下载测试点
猜你喜欢

MAUI Developer Day in GCR

QT:QSS自定义QTableView实例

Pour vous amener dans le monde des bases de données natives du cloud

8年测试工程师总结出来的《测试核心价值》与《0基础转行软件测试超全学习指南》

Overview of testing theory

那些一门心思研究自动化测试的人,后来怎样了?

硬 货 | 一改测试步骤代码就全写?为什么不试试用 Yaml实现数据驱动?

MAUI Developer Day in GCR

【Proteus仿真】74HC154 四线转12线译码器组成的16路流水灯

Multiple IO transfer - preamble
随机推荐
Qt:qss custom qspinbox instance
Large scale e-commerce project - environment construction
How does MySQL find the latest data row that meets the conditions?
Windows security center open blank
Qt:qss custom qscrollbar instance
软件测试必学基本理论知识——APP测试
Solutions of n-ary linear equations and their criteria
公司里只有一个测试是什么体验?听听他们怎么说吧
Some abilities can't be learned from work. Look at this article, more than 90% of peers
17K薪资要什么水平?来看看95后测试工程师的面试全过程…
Qt:qss custom qmenu instance
Word line and bit line
ExecutorException: Statement returned more than one row, where no more than one was expected.
In the middle of the year, I have prepared a small number of automated interview questions. Welcome to the self-test
嵌入式軟件測試怎麼實現自動化測試?
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
Nuget add reference error while installing packages
Qt:qss custom qlineedit instance
Cache routing component
栈,单调栈,队列,单调队列