Home > Software design >  Regression with a multi-variable function
Regression with a multi-variable function

Time:01-14

I have this code to fit a function with only one variable (x):

from scipy.optimize import curve_fit

def func(x, s, k, L,A):
    return A   (L * (1/(1 ((x/k)**(-s)))))

init_vals = [0.4,4, 100,50]
# fit your data and getting fit parameters
popt, pcov = curve_fit(func, xdata, ydata, p0=init_vals, bounds=([0,0.1, 1,0], [10,10, 1000,1000]))

But now I need to fit this one:

def func(x, s, k, L,A):
    return A   (L * (1/(1 (((b1*x1 b2*x2 b3*x3)/k)**(-s)))))

Where x is now f(x1,x2,x3)

CodePudding user response:

Should it be like this?

def func(x, s, k, L,A):
    return A   (L * (1/(1 (((b1*x[0] b2*x[1] b3*x[2])/k)**(-s)))))

and in this case xdata has to be (3,n) shaped array.

  •  Tags:  
  • Related