LMFIT:"值错误:输入包含nan值"当数据输入全部为浮点数时



我正在尝试曲线拟合一个数据集,我从和积分中得到,lmfit说它包含NaN值。

同样的数据被装scipy_curvefit,这是超级糟糕的。 我正在尝试这个库以获得更好的结果。

我尝试将我的 yData 和 xData 更改为一些简单的数组(您将在下面看到(,但遇到了同样的错误!

from lmfit import Model
def poly(x, a1,a2,a3,a4,a5):
    return a1+a2*x**a3+a4*x**a5
x=s
y=vrr
x=[0.,1.,2.,3.,5.,6.]
y=[4.,5.,6.,12.,3.,5.]
gmodel = Model(poly)
gmodel_parameters= gmodel.make_params()
gmodel_parameters['a1'].set(value=10)
gmodel_parameters['a2'].set(value=10)
gmodel_parameters['a3'].set(value=7)
gmodel_parameters['a4'].set(value=10)
gmodel_parameters['a5'].set(value=7)
result=gmodel.fit(x=x,data=y,params=gmodel_parameters)
plt.plot(x, y, 'k--')
plt.plot(x, result.best_fit, 'r-')
plt.show()

拟合指数时要小心。如果程序将此变量设置为小于零,则可能会出现 NaN 错误。阅读文档并尝试将 min=0 添加到 a3 和 a5 作为优化选项。

https://lmfit.github.io/lmfit-py/model.html#the-model-class

祝你好运!

最新更新