【发布时间】:2015-01-07 05:07:06
【问题描述】:
我有一组数据,我想拟合一个 幂律 函数
y=a*x**b
使用 python 库。另一个问题是x 和y 方向都有错误,我不知道哪个库可以让我适应这两个错误的函数。数据为here。我还尝试使用 gnuplot 进行拟合,但看起来不太有希望,而且我无法使用错误信息。
有什么建议吗?
【问题讨论】:
标签: python numpy scipy scikit-learn
我有一组数据,我想拟合一个 幂律 函数
y=a*x**b
使用 python 库。另一个问题是x 和y 方向都有错误,我不知道哪个库可以让我适应这两个错误的函数。数据为here。我还尝试使用 gnuplot 进行拟合,但看起来不太有希望,而且我无法使用错误信息。
有什么建议吗?
【问题讨论】:
标签: python numpy scipy scikit-learn
实际上,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()
【讨论】: