[SciPy-User] curve_fit and least squares
Wed Oct 7 00:36:50 CDT 2009
I am having trouble with fitting data to an exponential curve. I have an x-y
data series that I would like to fit to an exponential using least squares
and have access to the covariance matrix of the result. I summarize my
problem in the following example:
import numpy as np
import scipy as sp
from scipy.optimize.minpack import curve_fit
A, B = 5, 0.5
x = np.linspace(0, 5, 10)
real_f = lambda x: A * np.exp(-1.0 * B * x)
y = real_f(x)
ynoisy = y + 0.01 * np.random.randn(len(x))
exp_f = lambda x, a, b: a * np.exp(-1.0 * b * x)
# this line raises the error:
# RuntimeError: Optimal parameters not found: Both
# actual and predicted relative reductions in the sum of squares
# are at most 0.000000 and the relative error between two
# consecutive iterates is at most 0.000000
params, cov = curve_fit(exp_f, x, ynoisy)
I have tried to use the minpack.leastsq function directly with similar
results. I also tried taking the log and fitting to a line with no success.
The results are the same using scipy 0.7.1 as well as 0.8.0.dev5953. Am I
not using the curve_fit function correctly?
Heisenberg went for a drive and got stopped by a traffic cop. The cop asked,
"Do you know how fast you were going?" Heisenberg replied, "No, but I know
where I am."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User