当前位置:网站首页>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
边栏推荐
- 我,大厂测试员,降薪50%去国企,后悔了...
- QT: QSS custom qtableview instance
- Use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
- Flink-- custom function
- QT:QSS自定义QToolButton实例
- QT: QSS custom qtabwidget and qtabbar instances
- Cache routing component
- How can UI automated testing get out of trouble? How to embody the value?
- 《通信软件开发与应用》
- The highest monthly salary of 18K has a good "mentality and choice", and success is poor "seriousness and persistence"~
猜你喜欢
Take you into the cloud native database industry, Amazon Aurora
.Net Core-做一个微信公众号的排队系统
How to make a blood bar in the game
软件测试必学基本理论知识——APP测试
MAUI Developer Day in GCR
测试理论概述
Differences among norm, normalize and normalized in eigen
有些能力,是工作中学不来的,看看这篇超过90%同行
正常一英寸25.4厘米,在影像领域是16厘米
最高月薪18K 拥有好的“心态和选择”, 成功就差“认真和坚持”~
随机推荐
那些一門心思研究自動化測試的人,後來怎樣了?
Clion debug
Flink < --> Introduction to JDBC +with parameter
MySQL checks for automatic updates at 0:00 every day
15 software testing Trends Worthy of attention
值得关注的15种软件测试趋势
Redis notes 01: Introduction
If you always feel that you need to persist in learning English
How to realize automatic testing in embedded software testing?
Basic theoretical knowledge of software testing -- app testing
Extern keyword
Imread change image display size
嵌入式软件测试怎么实现自动化测试?
I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it
Matlab memory variable management command
MySQL -- index principle + how to use
Qt:qss custom qmenu instance
《通信软件开发与应用》
Differences among norm, normalize and normalized in eigen
嵌入式軟件測試怎麼實現自動化測試?