在Python中将经验数据拟合为幂律函数

8

我正在尝试使用 powerlaw 模块将实验数据的幂律分布拟合。我创建了以下数据,其遵循指数为 2 的幂律分布:

x = range(1,1000)
y = []

for i in x:
    y.append(i**(-2))

我希望拟合的幂律指数为2。但是结果偏离理论值太多:

    fitted_pl = powerlaw.Fit(y)

    fitted_pl.alpha
    Out[115]: 1.4017584065981563

请问为什么会出现这种情况?或者指出我在这里做错了什么?谢谢您的帮助!

1
当你写y.append(x**(-2))时,我认为你的意思是y.append(i**(-2)) - Brionius
1
你可能把线性回归 y(x) = k x^(-a) 和拟合概率分布 p(x) ~ (a-1) x^(-a) 中的指数混淆了吗?(注意:k->a 的变化是有意的。)powerlaw 模块解决的是第二个问题。 - DSM
@DSM,你说得完全正确!我混淆了两个非常不同的任务。非常感谢你指出这一点! - Moses Xu
1个回答

11

正如 @DSM 指出,powerlaw模块处理的是将指数拟合到从幂律分布中绘制/生成的值上,而不是拟合回归。为了帮助可能有类似困惑的人,以下是应该如何验证指数拟合:

## use a proper power law random number generator (or code your own) 
from networkx.utils import powerlaw_sequence
pl_sequence = powerlaw_sequence(1000,exponent=2.5)

fitted_pl = powerlaw.Fit(pl_sequence)

fitted_pl.alpha
Out[73]: 2.4709012785346314  ##close enough

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接