简体   繁体   English

如何在Python中进行幂曲线拟合?

[英]How to do power curve fitting in Python?

There is a question about exponential curve fitting, but I didn't find any materials on how to create a power curve fitting, like this: 关于指数曲线拟合存在一个问题,但我没有找到有关如何创建幂曲线拟合的任何材料,如下所示:

y = a*x^b

There is a way to do this in Excel, but is it possible in Python? 有一种方法可以在Excel中执行此操作,但是在Python中可以吗?

If you do an easy transformation you can apply the usual least squares regression. 如果执行简单的转换,则可以应用通常的最小二乘回归。

Instead of this equation: 代替此等式:

y = a*x^b

Take the natural log of both sides: 取双方的自然对数:

ln(y) = ln(a*x^b) = ln(a) + ln(x^b) = ln(a) + b*ln(x)

This is a linear equation in [ln(x), ln(y)] with slope b and intercept ln(a) . 这是[ln(x), ln(y)]的线性方程,斜率为b ,截距为ln(a)

You can use out of the box least squares fitting on the transformed data. 您可以使用开箱即用的最小二乘法拟合转换后的数据。

Just take logarithms: 只需取对数:

y = ax^b
log(y) = log(a) + b*log(x)

and use a linear fit for the pair log(x) and log(y) . 并为log(x)log(y)对使用线性拟合。 It will result on a line with slope b and intercept log(a) , just take exponential to obtain the parameter a . 它将在一条斜率为b的直线上截取log(a) ,只是采用指数获取参数a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM