当前位置:网站首页>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
边栏推荐
猜你喜欢

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

在职美团测试工程师的这八年,我是如何成长的,愿技术人看完都有收获
![[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials](/img/e0/c2b1fbe99939d44201401abf1b5a72.png)
[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials

Software testing e-commerce projects that can be written into your resume, don't you come in and get it?

Hard goods | write all the codes as soon as you change the test steps? Why not try yaml to realize data-driven?

Error installing the specified version of pilot

月薪过万的测试员,是一种什么样的生活状态?

Solve the problem that pycharm Chinese input method does not follow

我,大厂测试员,降薪50%去国企,后悔了...

I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
随机推荐
If you always feel that you need to persist in learning English
What are the strengths of "testers"?
Communication software development and Application
My understanding of testing (summarized by senior testers)
QT:QSS自定义 QProgressBar实例
Do you really need automated testing?
How to realize automatic testing in embedded software testing?
Multiple IO transfer - preamble
Qt:qss custom qlistview instance
我,大厂测试员,降薪50%去国企,后悔了...
Solutions of n-ary linear equations and their criteria
《通信软件开发与应用》
What experience is there only one test in the company? Listen to what they say
Some abilities can't be learned from work. Look at this article, more than 90% of peers
现在零基础转行软件测试还OK吗?
Snownlp emotion analysis
有些能力,是工作中学不来的,看看这篇超过90%同行
I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
MySQL checks for automatic updates at 0:00 every day
Qt:qss custom qspinbox instance