curve fitting zipf distribution matplotlib python

好久不见. 提交于 2021-02-18 17:11:13

问题


I tried to fit the following plot(red dot) with zipf distribution in python, F~x^(-a) I just simply chose a=0.56, and plot y = x^(-0.56) and I got the curve as follow: which is obviously wrong, don't know how I can do the curve fit

enter image description here


回答1:


Not sure what you are exactly looking for, but if you want to fit a model (function) to data, use scipy.optimize.curve_fit:

from scipy.optimize import curve_fit
from scipy.special import zetac


def f(x, a):
    return (x**-a)/zetac(a)


result = curve_fit(f, x, y, p0=[0.56])
p = result[0]

print p

If you don't trust the normalization, add a second parameter b and fit that as well.



来源:https://stackoverflow.com/questions/12037494/curve-fitting-zipf-distribution-matplotlib-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!