<div dir="ltr"><div dir="ltr"><div dir="ltr">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:<div><br></div><div><a href="https://github.com/djpine/linfit">https://github.com/djpine/linfit</a><br></div><div><br></div><div>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.</div><div><br></div><div><a href="mailto:pine@nyu.edu">pine@nyu.edu</a></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 24, 2019 at 7:04 PM Nils Geib <<a href="mailto:nilsc.becker@gmail.com">nilsc.becker@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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.<br></div><div><br></div><div>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).</div><div><br></div><div>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.</div><div><br></div><div>Cheers</div><div>Nils<br></div></div>_______________________________________________<br>SciPy-Dev mailing list<br>
<a href="mailto:SciPy-Dev@python.org" target="_blank">SciPy-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scipy-dev</a><br>
</blockquote></div></div>