向 curve_fit 添加边界:位置参数错误
Adding bounds to curve_fit: Positional arguments error
尝试对函数执行曲线拟合,使用 scipy curve_fit:
param_bounds=((-np.inf,-np.inf,0),(np.inf,np.inf,1))
OneCyParams, extras = curve_fit(func,xdata,ydata,bounds=param_bounds)
结果错误:
453 if weights is None:
454 def func_wrapped(params):
--> 455 return func(xdata, *params) - ydata
456 else:
457 def func_wrapped(params):
TypeError: OneCycle() takes 2 positional arguments but 4 were given
OneCycle 是我正在拟合的函数。
如果我删除 bounds 参数,这个错误就会消失。我做错了什么?
这个错误是因为相关函数只有一个参数。
适当调整param_bounds后,问题解决。
尝试对函数执行曲线拟合,使用 scipy curve_fit:
param_bounds=((-np.inf,-np.inf,0),(np.inf,np.inf,1))
OneCyParams, extras = curve_fit(func,xdata,ydata,bounds=param_bounds)
结果错误:
453 if weights is None:
454 def func_wrapped(params):
--> 455 return func(xdata, *params) - ydata
456 else:
457 def func_wrapped(params):
TypeError: OneCycle() takes 2 positional arguments but 4 were given
OneCycle 是我正在拟合的函数。
如果我删除 bounds 参数,这个错误就会消失。我做错了什么?
这个错误是因为相关函数只有一个参数。
适当调整param_bounds后,问题解决。