I am trying to use scipy.optimize to fit experimental data and got:
optimizeWarning: Covariance of the parameters could not be estimated
warnings.warn('Covariance of the parameters could not be estimated',
Here is the data I am trying to fit with exponential curve:
here is the part of a code where I am trying to fit a data:
# using curve_fit
from scipy.optimize import curve_fit
# defining a function
# exponential curve
def _1_func(x, a0,b0,beta):
"""
calculates the exponential curve shifted by bo and scaled by a0
beta is exponential
"""
y = a0 * np.exp( beta * x ) + b0
return y
# the code to fit
# initial guess for exp fitting params
numpoints = spectrum_one.shape[0]
x = F[1:numpoints] # zero element is not used
y = np.absolute(spectrum_one[1:numpoints])/signal_size
# making an initial guess
a0 = 1
b0 = y.mean()
beta = -100
p0 = [a0, b0, beta]
popt, pcov = curve_fit(_1_func, x, y, p0=p0)
perr = np.sqrt(np.diag(pcov)) # errors
print('Popt')
print(popt)
print('Pcov')
print(pcov)
UPDATE1: The result is:
Popt
[ 1.00000000e+00 7.80761109e-04 -1.00000000e+02]
Pcov
[[inf inf inf]
[inf inf inf]
[inf inf inf]]
UPDATE 2 - raw data for fitting is here in csv format: https://drive.google.com/file/d/1wUoS3Dq_3XdZwo3OMth4_PT-1xVJXdfy/view?usp=share_link
As I understand ic pcov has inf - it shows that curve_fit can't calculate the covariance and the popt parameters can't be used they are not optimal for this data..
If I visualize the data I have next results:
Why am I getting this type of error? (I thought it is an easy task for curve_fit)
Maybe I need to scale my data somehow?