Python's powerlaw package: AttributeError: 'powerlaw_gen' object has no attribute 'Fit'

314 views Asked by At

I am trying to built a power law graph on Python but it raises error as below:

AttributeError: 'powerlaw_gen' object has no attribute 'Fit'

Even when I picked a standard data sample from an example posted by another user (@AcCap) on this forum in 2016, now it raised the same error. python plot and powerlaw fit

Here's the sampling codes:

import powerlaw
d=[6, 4, 0, 0, 0, 0, 0, 1, 3, 1, 0, 3, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3,2,  3, 3, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 1,0, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1,3, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 2, 3, 2, 1, 0, 0, 0, 1, 2]
fit = powerlaw.Fit(numpy.array(d)+1,xmin=1,discrete=True)
fit.power_law.plot_pdf( color= 'b',linestyle='--',label='fit ccdf')
fit.plot_pdf( color= 'b')

print('alpha= ',fit.power_law.alpha,'  sigma= ',fit.power_law.sigma)

Anyone has any idea? Thank you so much!

1

There are 1 answers

0
Nayeli On

Try installing first this:

pip install powerlaw==1.3.4

I had the same error, but this solved it!