Reputation: 321
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?
Upvotes: 4
Views: 12032
Reputation: 400
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)
. It will result on a line with slope b
and intercept log(a)
, just take exponential to obtain the parameter a
.
Upvotes: 3
Reputation: 308998
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.
Upvotes: 8