mak*_*ghi 12 python curve-fitting scipy
我正在scipy.optimize.curve_fit()
以迭代的方式使用.
我的问题是,当它无法适应参数时,整个程序(以及迭代)停止,这就是它给出的错误:
RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 800.
我明白为什么它无法适应.我的问题是,有什么办法可以在Python 3.2.2中编写程序来忽略这种情况而只是继续吗?
tal*_*ies 15
您可以使用标准Python异常处理来捕获curve_fit
在优化无法找到解决方案时引发的错误.所以类似于:
try:
popt,pcov = scipy.optimize.curve_fit(f, xdata, ydata, p0=None, sigma=None)
except RuntimeError:
print("Error - curve_fit failed")
Run Code Online (Sandbox Code Playgroud)
该构造将让您捕获并处理由此引发的错误情况,curve_fit
而不会使程序中止.