I am trying to fit a model to some data. The independent variables are called A
and B
, and they are columns in a Pandas DataFrame. I am trying to fit with two parameters against y
in the data frame.
Previously, with curve_fit
from Scipy, I could do:
def fun(X, p1, p2):
A, B = X
return np.exp(p1*A) + p2*B
X = (df['A'].tolist(), df['B'].tolist())
popt, pcov = curve_fit(fun, X, df['y'].tolist())
But now, I'm using lmfit
, where I cannot simply "pack" the independent variables like with curve_fit
:
def fun(A, B, p1 = 1, p2 = 1):
return np.exp(p1*A) + p2*B
model = Model(fun, independent_vars=['A', 'B'])
How do I run model.fit()
here? The FAQ is not really helpful—what do I have to flatten in the first place?