Set power law for empirical data in Python

I am experimenting with setting the power law for empirical data using the powerlaw module. I created the following data following the power law of the distribution of indicator 2:

x = range(1,1000) y = [] for i in x: y.append(i**(-2)) 

I expect that the law with the established degree has an exponent of 2. However, the resulting exponent is very different from the theoretical value:

  fitted_pl = powerlaw.Fit(y) fitted_pl.alpha Out[115]: 1.4017584065981563 

Could you advise why this is happening, or indicate what I did wrong here?

Thanks for your kind reply!

+7
python power-law
source share
1 answer

As @DSM pointed out, the powerlaw module deals with fitting the exponent to the values ​​obtained / generated from the power law distribution, rather than setting the regression. To help people who may have similar confusion, the following shows how to check the exponent setting:

 ## 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 
+8
source share

All Articles