Billy Matlock
Billy Matlock

Reputation: 350

LMFIT: ' ValueError: The input contains nan values'when Data Input is all Float

I'm trying to Curve-Fit a data-set, that I got from and Integration, which lmfit says contains NaN value.

The same Data were fitted with scipy_curvefit, that was SUPER Bad. I'm trying this library for some better results.

I tried to change my yData and xData to some simple arrays (you will see below) and got the same error!

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()

Upvotes: 2

Views: 313

Answers (1)

Jamil KR
Jamil KR

Reputation: 66

Be careful when you fit an exponent. If the program sets this variable to less than zero, you may have a NaN error. Read the documentation and try to add min=0 to a3 and a5 as a optimization option.

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

Good luck!

Upvotes: 2

Related Questions