random.
binomial
从二项式分布中提取样本。
样本从二项分布中提取,其中n个整数大于等于0,p在区间内,n个试验和p成功概率为指定参数。 [0,1] . (n可以作为浮点输入,但被截断为使用中的整数)
注解
新代码应该使用 binomial A方法 default_rng() 请参阅 快速启动 .
default_rng()
分布的参数,>=0。也接受浮动,但它们将被截断为整数。
分布的参数,>=0且<=1。
输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 n 和 p 都是标量。否则, np.broadcast(n, p).size 取样。
(m, n, k)
m * n * k
None
n
p
np.broadcast(n, p).size
从参数化二项分布中提取样本,其中每个样本等于n次试验的成功次数。
参见
scipy.stats.binom
概率密度函数、分布或累积密度函数等。
Generator.binomial
应该用于新代码。
笔记
二项分布的概率密度是
System Message: WARNING/2 (p(n)=\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-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 ...\binom n n p^n(1-p)^ n-n,\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 512 bytes). Transcript written on math.log.
在哪里? 是试验次数, 是成功的概率,以及 是成功的次数。
当用随机样本估计一个群体中某一比例的标准误差时,正态分布很好地工作,除非产品p n <=5, where p = population proportion estimate, and n = number of samples, in which case the binomial distribution is used instead. For example, a sample of 15 people shows 4 who are left handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27 15=4,所以在这种情况下应该使用二项分布。
工具书类
Dalgaard,Peter,“R导论统计”,Springer Verlag,2002年。
Glantz,Stanton A.,《生物统计学入门》,McGraw-Hill,第五版,2002年。
Lenner,Marvin,“基础应用统计学”,Bogden和Quigley,1972年。
二项分布〉,摘自《数学世界——一个Wolfram网络资源》。http://mathworld.wolfram.com/binomialddistribution.html
维基百科,“二项分布”,https://en.wikipedia.org/wiki/binomial_distribution
实例
从分发中抽取样本:
>>> n, p = 10, .5 # number of trials, probability of each trial >>> s = np.random.binomial(n, p, 1000) # result of flipping a coin 10 times, tested 1000 times.
一个现实世界的例子。一家公司钻了9口野生猫科石油勘探井,每口井的成功概率估计为0.1。所有九口井都失败了。发生这种情况的可能性有多大?
让我们对模型进行20000次试验,并计算产生零正结果的数字。
>>> sum(np.random.binomial(9, 0.1, 20000) == 0)/20000. # answer = 0.38885, or 38%.