当前位置:网站首页>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
边栏推荐
- I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
- Flink-- custom function
- 使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
- Interviewer: what is the internal implementation of the list in redis?
- QT:QSS自定义 QTabWidget 和 QTabBar实例
- 【Proteus仿真】74HC154 四线转12线译码器组成的16路流水灯
- The highest monthly salary of 18K has a good "mentality and choice", and success is poor "seriousness and persistence"~
- 独家分析 | 关于简历和面试的真 相
- Game test related tests a hero's skills (spring moves are asked more questions)
- Matlab memory variable management command
猜你喜欢

.Net Core-做一个微信公众号的排队系统

Interviewer: what is the internal implementation of the list in redis?

QT: QSS custom qtabwidget and qtabbar instances

How does MySQL find the latest data row that meets the conditions?

测试理论概述

Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
正常一英寸25.4厘米,在影像领域是16厘米

Basic theoretical knowledge of software testing -- app testing

ByteDance layoffs, test engineers were almost destroyed: how terrible is the routine behind the recruitment of large factories?

做软件测试三年,薪资不到20K,今天,我提出了辞职…
随机推荐
文件上传下载测试点
现在零基础转行软件测试还OK吗?
The role and necessity of implementing serializable interface
In the middle of the year, I have prepared a small number of automated interview questions. Welcome to the self-test
IIS修改配置信息后不生效
How can UI automated testing get out of trouble? How to embody the value?
独家分析 | 关于简历和面试的真 相
Day 7 small exercise
Latest sales volume of pinduoduo
How does MySQL find the latest data row that meets the conditions?
最高月薪18K 拥有好的“心态和选择”, 成功就差“认真和坚持”~
Qt:qss custom qpprogressbar instance
有些能力,是工作中学不来的,看看这篇超过90%同行
多路IO转接——前导
QT:QSS自定义 QStatusBar实例
Hard goods | write all the codes as soon as you change the test steps? Why not try yaml to realize data-driven?
snownlp情感分析
10. Nacos source code construction
Logstash backup tracks the data records reported
Extern keyword