当前位置:网站首页>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 ,ppf
yescdf
The 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
边栏推荐
- QT:QSS自定义 QSlider实例
- Qt:qss custom QSlider instance
- Snownlp emotion analysis
- Qt:qss custom qpprogressbar instance
- What is the salary level of 17k? Let's take a look at the whole interview process of post-95 Test Engineers
- 年中了,准备了少量的自动化面试题,欢迎来自测
- Que se passe - t - il ensuite pour ceux qui se sont concentrés sur les tests automatisés?
- 正常一英寸25.4厘米,在影像领域是16厘米
- 使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
- 我对测试工作的一些认识(资深测试人员总结)
猜你喜欢
软件测试——Redis数据库
Snownlp emotion analysis
11. Provider service registration of Nacos service registration source code analysis
How to monitor the incoming and outgoing traffic of the server host?
ByteDance layoffs, test engineers were almost destroyed: how terrible is the routine behind the recruitment of large factories?
Basic theoretical knowledge of software testing -- app testing
Cache routing component
我,大厂测试员,降薪50%去国企,后悔了...
Software testing redis database
Lecture 1 number field
随机推荐
First line of code kotlin notes
软件测试(测试用例)编写之俗手、本手、妙手
UI自动化测试如何走出困境?价值又如何体现?
Typescript learning summary
Windows security center open blank
2022 pinduogai 100000 sales tutorial
How to realize automatic testing in embedded software testing?
QT:QSS自定义QToolBar和QToolBox实例
Wechat applet training notes 1
Wechat applet training 2
Solve the problem that pycharm Chinese input method does not follow
I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
QT: QSS custom qtableview instance
QT:QSS自定义QGroupBox实例
QT: QSS custom qsplitter instance
Promoted, colleagues become subordinates and don't cooperate with work
QT:QSS自定义QListView实例
QT:QSS自定义QTableView实例
Exclusive analysis | truth about resume and interview
测试Leader应该做哪些事