问题描述
如何计算给定均值的正态分布概率,Python 中的标准?我总是可以根据这个问题中的 OP 那样的定义明确地编写我自己的函数:用 Python 计算分布中随机变量的概率
只是想知道是否有库函数调用将允许您执行此操作.在我的想象中它会是这样的:
nd = NormalDistribution(mu=100, std=12)p = nd.prob(98)
Perl 中有一个类似的问题:如何计算 Perl 中给定正态分布的点的概率?.但是我在 Python 中没有看到.
Numpy
有一个 random.normal
功能,但它就像采样,不完全是我想要的.
[需要注意的一件事——只是一个提示——是参数传递有点宽泛.因为代码的设置方式,如果不小心写了 scipy.stats.norm(mean=100, std=12)
而不是 scipy.stats.norm(100, 12)
或 scipy.stats.norm(loc=100, scale=12)
,然后它会接受它,但默默地丢弃那些额外的关键字参数并为您提供默认值 (0,1)]
How to calculate probability in normal distribution given mean, std in Python? I can always explicitly code my own function according to the definition like the OP in this question did: Calculating Probability of a Random Variable in a Distribution in Python
Just wondering if there is a library function call will allow you to do this. In my imagine it would like this:
nd = NormalDistribution(mu=100, std=12)
p = nd.prob(98)
There is a similar question in Perl: How can I compute the probability at a point given a normal distribution in Perl?. But I didn't see one in Python.
Numpy
has a random.normal
function, but it's like sampling, not exactly what I want.
There's one in scipy.stats:
>>> import scipy.stats
>>> scipy.stats.norm(0, 1)
<scipy.stats.distributions.rv_frozen object at 0x928352c>
>>> scipy.stats.norm(0, 1).pdf(0)
0.3989422804014327
>>> scipy.stats.norm(0, 1).cdf(0)
0.5
>>> scipy.stats.norm(100, 12)
<scipy.stats.distributions.rv_frozen object at 0x928352c>
>>> scipy.stats.norm(100, 12).pdf(98)
0.032786643008494994
>>> scipy.stats.norm(100, 12).cdf(98)
0.43381616738909634
>>> scipy.stats.norm(100, 12).cdf(100)
0.5
[One thing to beware of -- just a tip -- is that the parameter passing is a little broad. Because of the way the code is set up, if you accidentally write scipy.stats.norm(mean=100, std=12)
instead of scipy.stats.norm(100, 12)
or scipy.stats.norm(loc=100, scale=12)
, then it'll accept it, but silently discard those extra keyword arguments and give you the default (0,1).]
这篇关于如何计算给定均值和正态分布的概率标准差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!