gpt4 book ai didi

python - 对具有 x 和 y 误差的数据拟合幂律函数

转载 作者:太空宇宙 更新时间:2023-11-04 05:57:42 24 4
gpt4 key购买 nike

我有一组数据,我想拟合一个幂律函数

y=a*x**b

使用 python 库。另一个问题是我在 xy 方向上都有错误,我不知道哪个库可以让我适应这两个错误的功能。数据为here .我也尝试使用 gnuplot 来进行拟合,但看起来不太有前途,而且我无法使用错误信息。 enter image description here

有什么建议吗?

最佳答案

实际上,scipy 有一个 Orthogonal distance regression包裹。

这是他们的线性拟合示例,您所要做的就是将 f 更改为幂律:

from scipy.odr import Model, Data, ODR

def f(p, x):
'''Linear function y = m*x + b'''
# B is a vector of the parameters.
# x is an array of the current x values.
# x is in the same format as the x passed to Data or RealData.
#
# Return an array in the same format as y passed to Data or RealData.
return p[0] * x ** p[1]

linear = Model(f)
#sx, sy are arrays os error estimates
mydata = Data(x, y, wd=1./power(sx,2), we=1./power(sy,2))
#beta0 are the inital parameter estimates
myodr = ODR(mydata, linear, beta0=[10, -1.0])
myoutput = myodr.run()
myoutput.pprint()

关于python - 对具有 x 和 y 误差的数据拟合幂律函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26851533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com