I am trying to fit an exponential decay on empirical data.
However, it seems pretty inaccurate.
I was wondering the cause of this misfunction.
Is it because of the log scale on y ? I made it to better visualize and I would like to keep it.
Because of extreme values on y ?
from scipy.optimize import curve_fit
def model_func(x, a, k, b):
return a * np.exp(-k*x) + b
pos_freq = pos_freq[:-1]
mpow = mpow[:-1]
pos_freq = pos_freq * 100
p0 = (1.,1.e-5,1.) # starting search koefs
opt, pcov = curve_fit(model_func, pos_freq, mpow, p0)
a, k, b = opt
x2 = np.linspace(0, 70, 500)
y2 = model_func(x2, a, k, b)
fig, ax = plt.subplots()
ax.plot(x2, y2, color='r', label='Fit. func: $f(x) = %.3f e^{%.3f x} %+.3f$' % (a,k,b))
ax.plot(pos_freq, mpow,'bo', label='data with noise')
ax.legend(loc='best')
ax.set_yscale('log')
plt.show()