numpy.random.Generator.negative_binomial

方法

random.Generator.negative_binomial(n, p, size=None)

从负二项分布中提取样本。

样本是从负二项分布中提取的,具有指定的参数, n 成功与 p 成功概率,其中 n 大于0且 p 在间隔(0,1)中。

参数
n浮点数或类似浮点数的数组

分布参数,>0。

p浮点数或类似浮点数的数组

分布的参数。必须满足0<p<=1。

sizeint或int的元组,可选

输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 np 都是标量。否则, np.broadcast(n, p).size 取样。

返回
outndarray或scalar

从参数化负二项分布中提取样本,其中每个样本等于n,即达到n次成功之前发生的失败数。

笔记

负二项分布的概率质量函数是

System Message: WARNING/2 (P(N;N,P)=\frac{\Gamma(N+N)}{N!\伽马(n)}p ^{n}(1-p)^{n},)

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ! (U+FF01) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Undefined control sequence. <argument> N!\� ��马(n) l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BC. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BD. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character 马 (U+9A6C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ! (U+FF01) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Undefined control sequence. <argument> N!\� ��马(n) l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BC. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BD. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character 马 (U+9A6C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�(n)}p ^{n}(1-p)^{n},\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 480 bytes). Transcript written on math.log.

在哪里? n 是成功的次数, p 是成功的概率, N+n 是试验次数,以及 \Gamma 是伽马函数。什么时候? n 是一个整数, \frac{{\Gamma(N+n)}}{{N!\Gamma(n)}} = \binom{{N+n-1}}{{N}} ,这是pmf中该术语更常见的形式。负二项分布给出了N次成功的N次失败的概率,最后一次试验成功。

如果一个人反复掷骰子直到第三次出现“1”,那么出现在第三次“1”之前的非“1”数的概率分布是负二项分布。

工具书类

1

负二项式分布〉,摘自《数学世界——一个Wolfram网络资源》。http://mathworld.wolfram.com/negative二项分布.html

2

维基百科,“负二项分布”,https://en.wikipedia.org/wiki/negative_binomial_distribution

实例

从分发中抽取样本:

一个现实世界的例子。一家公司钻探野生猫石油勘探井,每口井的成功概率估计为0.1。每口连续井成功一次的概率是多少,即钻完5口井、钻完6口井等后一次成功的概率是多少?

>>> s = np.random.default_rng().negative_binomial(1, 0.1, 100000)
>>> for i in range(1, 11): 
...    probability = sum(s<i) / 100000.
...    print(i, "wells drilled, probability of one success =", probability)