# Fitting using curve_fit of scipy in python gives totally different answer for 1/t and t

I was trying to fit some data to a single degree exponential decay function but a*exp(-x*t) and a*exp(-x/t) gives completely different answers with the latter not at all fitting the data well. The code:

def func(x, a1, t1, c):
return a1 * numpy.exp(-x*t1) + c

interp_x = np.arange(low,high+dx,dx)
popt, pcov = scipy.optimize.curve_fit(func, x, y,maxfev=10000)
curve = func(interp_x,*popt)


This was the data used:

0.050   365.104
0.100   331.764
0.200   299.508
0.500   241.281
0.700   188.579
1.000   144.728
2.000   73.2627

• What were the initial estimates used in each case? Jun 12 at 19:06
• @nicoguaro I dd not use any. I just gave the scipy.optimize.curve_fit() and the data as input and used values returned by it, I hope I am clear. Jun 13 at 11:06
• It may help if you put your full code in the question. Jun 13 at 20:12
• Why do you expect similar fits from both models? Jun 14 at 3:23
• In that case, the difference is most likely do to the initial parameter that the fitting routine starts with. Jun 16 at 19:03

Curve fitting can be very sensitive to your initial guess for each parameter. Because you don't specify a guess in your code, all of these parameters start with a value of 1. Comparing with the converged results for the t fitting, while t is actually pretty close to 1, the other parameters are much further away. Its mostly just luck that the t value didn't drift too far away while searching for appropriate values for a and c.
The 1/t fit was not so lucky and the search led it far away from the good solution obtained by the t fit. However a better initial guess can fix this. Using the a and c values from the t fit as an initial guess leads to the same solutions. I hadn't tried this, but I suspect even just providing a better guess for c (say 400) would probably be enough to make both fits match.