Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 646
Sergey Gulbin Avatar asked Oct 11 '25 18:10

Sergey Gulbin


1 Answers

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).

You can use out of the box least squares fitting on the transformed data.

like image 151
duffymo Avatar answered Oct 16 '25 11:10

duffymo