我是python的新手我有这个代码我想使用子类lmfit.models并实现一个猜测方法,
class DecayingSineModel():
def __init__(self, *args, **kwargs):
def decaying_sine(self, x, ampl, offset, freq, x0, tau):
return ampl * np.sin((x - x0)*freq) * np.exp(-x/tau) + offset
super(DecayingSineModel, self).__init__(decaying_sine, *args, **kwargs)
def pset(param, value):
params["%s%s" % (self.prefix, param)].set(value=value)
def guess(self, data, **kwargs):
params = self.make_params()
pset("ampl", np.max(data) - np.min(data))
pset("offset", np.mean(data))
pset("freq", 1)
pset("x0", 0)
pset("tau", 1)
return lmfit.models.update_param_vals(params, self.prefix, **kwargs)
sp = DecayingSineModel()
params = sp.guess(y, x=x)
fit = sp.fit(y, params, x=x)
我收到以下错误我收到 的错误我收到的错误图像在此地址中