9
$\begingroup$

I'm trying to understand the difference between these two methods.

Both seem to be able to be used to find optimal parameters for an non-linear function using constraints and using least squares.

However, they are evidently not the same because curve_fit results do not correspond to a third solver whereas least_squares does.

Can someone explain the difference?

$\endgroup$

1 Answer 1

10
$\begingroup$

There is no fundamental difference between curve_fit and least_squares. Moreover, if you don't use method = 'lm'they do exactly the same thing. You can check it in a source code of curve_fit fucntion on a Github:

if method == 'lm':
    ...
    res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)
    ...
else:
   ...
    res = least_squares(func, p0, jac=jac, bounds=bounds, method=method,
                        **kwargs)
   ...

So, curve_fit is just a wrapper around least_squares. I've just checked them out and I've got the same results from both.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.