[SciPy-Dev] curve_fit() should require initial values for parameters

David J Pine djpine at gmail.com
Thu Jan 24 16:21:33 EST 2019


Five years ago I submitted a linear fitting routine for SciPy so that
people could have an alternative to curve_fit when they wanted to fit a
linear model.  Here it is:

https://github.com/djpine/linfit

Some people felt it was redundant with linear regression routines in
scipy.stats.  However, the linear regression routine in scipy.stats does
not offer the same capabilities as curve_fit for including error estimation
(data weighting) so it may not meet the needs of users who typically use
curve_fit.  The above routine is meant to remedy that.

pine at nyu.edu



On Thu, Jan 24, 2019 at 7:04 PM Nils Geib <nilsc.becker at gmail.com> wrote:

> Just one small remark: in my experience many users utilize curve_fit to
> fit linear models (models that are linear in the fit parameters, e.g. f(x)
> = a * exp(-x) + b * exp(-x^2)). In this case the linear least squares
> problem can be solved uniquely without providing initial values for a and
> b. Even though curve_fit employs a general nonlinear least squares solver
> it should be able to find the global minimum for virtually all starting
> values (although I have not comprehensively tested it). On the other hand
> when the model is truly nonlinear the initial values of curve_fit fail with
> very high probability.
>
> One may argue that using curve_fit for such cases is not the right choice.
> However, scipy does not provide a convenient interface such as curve_fit
> for linear models (as far as I know). And users who are not aware that a
> nonlinear least squares solver requires good initial values may also not be
> aware of the difference between linear and nonlinear models. (When I teach
> I regularly encounter the misconception that models that are nonlinear in
> the independent variable, e.g., x, require a nonlinear solver).
>
> Long story short: when deprecating the initial choice for p0 it may be
> worthwile to also consider providing a convenient interface for lsq_linear
> that is similar to curve_fit and does not require initial values.
>
> Cheers
> Nils
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20190125/89d18c39/attachment-0001.html>


More information about the SciPy-Dev mailing list