1

Data

df = pandas.read_csv(temp.csv, header=1)

def func(x1,x2,x3,a,b1,b2,b3,c):
    #return(a*np.exp(b1*x1)*np.exp(b2*x2)*np.exp(b3*x3)+c)
    return(a*np.exp(b1*x1) + b2*x2 + b3*x3 + c

def formula_tester(BIO, VAR1, VAR2, VAR3):
    X = scipy.array([VAR1, VAR2, VAR3])
    Y = scipy.array(BIO)
    popt, pcov = curve_fit(func, X, Y)
    return(popt)

Y = df['Biomass'] 
variable1 = df['F_cv']
variable2 = ln(df['F_d50'])
variable3 = ln(df['L_d50'])
parameters = formula_tester(Y, variable1, variable2, variable3)
parameters

This returns the error message

Improper Input: N=7 must not exceed M=3

I have read the Help and a few Stack Overflow questions. The prior answers either correct minor typos or prove unhelpful when tried (np.concatenate).

Running the script with a try/except, where except returns the lengths of the various variable arrays, reveals all to have length 162. Where is the N=7 coming from? And I did think I was asking for 5 parameters, not 3. Perhaps the exponential function is set up wrong?

J Kelly
  • 480
  • 1
  • 5
  • 15

1 Answers1

2

From the doc of curve_fit:

The model function, f(x, …). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.

Here the independent variable has three components. The model should look like

def func(x, a, b1, b2, b3, c):
    return a*np.exp(b1*x[0]) + b2*x[1] + b3*x[2] + c