【问题标题】:How to get the standard deviation from the fitted distribution in scipy?如何从scipy中的拟合分布中获得标准偏差?
【发布时间】:2016-12-16 17:34:33
【问题描述】:

我正在尝试拟合多个分布并获得每个分布的标准差。然而,对于标准偏差,大量分布会返回 inf 或 Nan。获取我正在做的拟合分布方差的方法是否正确?有没有更好的办法?为什么是南人?这就是我所做的:

param = distribution.fit(data)
arg = param[:-2]
loc = param[-2]
scale = param[-1]

if len(arg)>0:
     std = np.sqrt(distribution.stats(arg, loc, scale, moments='v')[0]))
else:
     std = np.sqrt(distribution.stats(loc, scale, moments='v')[0]))

我还跳过了在拟合数据时会产生警告的分布。

更新 1: 比如distribution = scipy.stats.beta,我得到[ nan nan],参数如下:

arg: (32.198726690922953, 15883184.284202889)
loc: -33527.5754686
scale: 35484135514.4 

【问题讨论】:

  • 请提供更多细节。提供data,并显示哪个分布给出infnan
  • 感谢@WarrenWeckesser 的提醒,我会将分布添加到问题中,但我的代码是否正确?或者有更好的方法来获取我的数据的标准差。

标签: python scipy statistics data-fitting


【解决方案1】:

beta 发行版的variance 是:

a * b / [ (a + b)^2 * (a + b + 1) ]

所以标准差是它的平方根。获取ab

a = scipy.stats.beta.fit(data)[0]
b = scipy.stats.beta.fit(data)[1]

请注意,您可以始终使用 np.std(data) 计算数据的标准差(没有任何拟合分布)。

【讨论】:

  • 我知道,但我正在遍历分布列表。因此,我一直在寻找一种适用于任何发行版的通用方法,内置的东西。
【解决方案2】:

我在 Stack Overflow 上问了一个不同的问题,并得到了一个回答这个问题的解决方案。事实证明,我传递的参数被 scipy.这是答案的链接:

isinfmu-error-in-scipy-stats-when-calling-std-for-exponweib

【讨论】:

    猜你喜欢
    • 2016-07-24
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多