Python的Power Law Fit
我有两列数据, x
和 y
。我有兴趣进行表格的power Law拟合: y = a+b*x^c
。 Python中是否有包装?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有两列数据, x
和 y
。我有兴趣进行表格的power Law拟合: y = a+b*x^c
。 Python中是否有包装?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
以下将两个参数与
scipy.optimize.curve_fit 是最小二乘或最小值的包装器。
如果您有统计背景,请参阅
so How-to-to-properly-fit-data -to-a-power-law-in-python 。
The following fits two parameters with scipy least_squares (which is really nice, really powerful);
you can easily modify it for a + b x^c --
scipy.optimize.curve_fit is a wrapper for least_squares or leastsq.
If you have some background in statistics, see
SO how-to-properly-fit-data-to-a-power-law-in-python.
首先定义模型函数,
我们可以使用从Scipy找到可以最佳拟合的A,B和C的值。
“ POPT”是A,B和C的值列表,它给出了最佳拟合度(请注意,无法保证存在解决方案,或者您获得的解决方案是最佳的解决方案)。
“ PCOV”是矩阵。其对角线的平方根是对溶液不确定性的度量。
“初始猜测”是在拟合算法的第一次迭代中用作A,B和C的初始值的三个数字的列表。您必须提供值。
您可以传递到curve_fit的另一个关键字是“界限”。这将限制算法搜索参数a,b和c的值的范围。 “界限”可以列出两个列表。第一个列表是每个参数的底部限制,而第二个列表是针对顶部界限的。
这是一个例子。
您应该得到
Start by defining a model function
We can use the curve_fit function from scipy to find the values for a, b, and c which give the best fit.
'popt' is a list of the values for a, b, and c which gives the best fit (notice that there is no guarantee a solution exists or that the one you get is the optimal one).
'pcov' is a matrix. The square root of its diagonal is a measure of the uncertainty of the solution.
'initial guess' is a list of three numbers that serve as initial values for a, b, and c in the first iteration of the fitting algorithm. You must provide the values.
Another keyword that you can pass to curve_fit is 'bounds'. This serves to limit the range the algorithm searches for values for the parameters a, b, and c. 'bounds' can take a tuple of two lists. The first list are the bottom limits for each parameter, while the second list is for the top bounds.
Here is an example.
You should get