曲线拟合 zipf 分布 matplotlib python [英] curve fitting zipf distribution matplotlib python

查看:61
本文介绍了曲线拟合 zipf 分布 matplotlib python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Python中的Zipf分布PDF F〜x ^(-a)拟合以下图(红点).我简单地选择了a=0.56并绘制了y = x^(-0.56),我得到了如下所示的曲线.

I tried to fit the following plot(red dot) with the Zipf distribution PDF in Python, F~x^(-a). I simply chose a=0.56 and plotted y = x^(-0.56), and I got the curve shown below.

曲线显然是错误的.我不知道如何进行曲线拟合.

The curve is obviously wrong. I don't know how to do the curve fitting.

推荐答案

不确定您到底在寻找什么,但如果您想将模型(函数)拟合到数据,请使用 scipy.optimize.curve_fit:

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

如果您不信任规范化,请添加第二个参数 b 并使其适合.

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

这篇关于曲线拟合 zipf 分布 matplotlib python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆