[SciPy-User] Leastsq questions
Charles R Harris
Mon Jun 14 20:49:07 CDT 2010
On Mon, Jun 14, 2010 at 2:28 PM, Timothy Kinney <email@example.com>wrote:
> Scipy Community,
> I am using the scipy leastsq method to fit some cooling data, such
> that the temperature is defined by an exponential decay function
> (Newton's Cooling Law). However, there are some other factors which
> also influence the cooling rate and I am attempting to account for
> them in the cooling law. I have some questions about leastsq:
> 1) When I fit the data in Excel I get a different fit than when I fit
> the same data in Scipy. Why is this? The fits are not very different,
> but they are consistently different.
It is impossible to know without a good deal more information, i.e., what is
your model, how is it parameterized, what is the data, when do the
iterations stop, and, if the parameters aren't sufficiently independent over
the data set, what is the required condition number. I suspect the latter is
coming into play here.
> 2) How do I calculate the goodness of fit (R squared) for the leastsq
> algorithm? I think it's just the sum of the squared errors divided by
> something, but shouldn't this be easily called from the output?
If you are using the function correctly, then you already have an error
function that returns the residuals. Note that it is also available in the
I would like to iterate over a computation where I change one of the
> values and see how it effects the goodness of the fit. I'm not sure
> how to calculate the r-squared from the plsq that is returned from
> My goal is to find the value of a single parameter that best optimizes
> the leastsq fit. Should I be using one of the other optimizing
> functions for this instead? Basically, I calculate a value from the
> theory and compare it to the experimental data. I fit the theory to
> the data and look at the r-squared. I want to adjust the theory to
> account for some other factors by adjusting one of the terms in a way
> that maximizes the goodness of fit.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User