scipy,对数正态分布 - 参数 [英] scipy, lognormal distribution - parameters
问题描述
我想使用 python scipy.stats.lognormal.fit
将对数正态分布拟合到我的数据中.根据手册,fit
返回 shape, loc, scale 参数.但是,对数正态分布通常只需要两个参数:均值和标准差.
I want to fit lognormal distribution to my data, using python scipy.stats.lognormal.fit
. According to the manual, fit
returns shape, loc, scale parameters. But, lognormal distribution normally needs only two parameters: mean and standard deviation.
如何解释 scipy fit
函数的结果?如何获得均值和标准差.
How to interpret the results from scipy fit
function? How to get mean and std.dev.?
推荐答案
scipy 中的分布以通用方式编码,包含两个参数 location 和 scale,因此 location 是参数 (loc
)将分布向左或向右移动,而 scale
是压缩或拉伸分布的参数.
The distributions in scipy are coded in a generic way wrt two parameter location and scale so that location is the parameter (loc
) which shifts the distribution to the left or right, while scale
is the parameter which compresses or stretches the distribution.
对于两个参数对数正态分布,mean"和std dev"分别对应log(scale
)和shape
(可以让loc=0
).
For the two parameter lognormal distribution, the "mean" and "std dev" correspond to log(scale
) and shape
(you can let loc=0
).
以下说明如何拟合对数正态分布以找到两个感兴趣的参数:
The following illustrates how to fit a lognormal distribution to find the two parameters of interest:
In [56]: import numpy as np
In [57]: from scipy import stats
In [58]: logsample = stats.norm.rvs(loc=10, scale=3, size=1000) # logsample ~ N(mu=10, sigma=3)
In [59]: sample = np.exp(logsample) # sample ~ lognormal(10, 3)
In [60]: shape, loc, scale = stats.lognorm.fit(sample, floc=0) # hold location to 0 while fitting
In [61]: shape, loc, scale
Out[61]: (2.9212650122639419, 0, 21318.029350592606)
In [62]: np.log(scale), shape # mu, sigma
Out[62]: (9.9673084420467362, 2.9212650122639419)
这篇关于scipy,对数正态分布 - 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!