[SciPy-Dev] least squares solvers

Robert Kern robert.kern@gmail....
Fri Jan 27 04:12:54 CST 2012


On Fri, Jan 27, 2012 at 09:58, Sturla Molden <sturla@molden.no> wrote:
> On 27.01.2012 10:47, Sturla Molden wrote:
>
>> Why is the non-linear LS solver in sp.optimize called leastsq, whereas
>> the linear solver in sp.linalg is called lstsq? Wouldn't a consistent
>> name be better?
>
> Also I think the docstring for sp.optimize.leastsq should refer to the
> linear solver, because I have seen multiple examples of people using
> sp.optimize.leastsq to solve linear systems.

The docstring editor is here:

http://docs.scipy.org/scipy/docs/scipy.optimize.minpack.leastsq/#leastsq

You will need a login. To get edit privileges, post a new thread to
this list giving the username you have chosen.

>> sp.linalg.lstsq uses SVD, by lapack driver *gelss. If we don't need
>> singular values, solving by QR is faster (lapack driver *gels).
>>
>> (I actually use Fortran just to get DGELS instead of DGELSS.)
>
> Another thing is that the terminology here could be confusing. The
> docstring for lstsq uses the naming convention from linear algebra, i.e.
> sp.linalg.lstsq(a, b) will minimize 2-norm |b - Ax|.
>
> Those needing it for statistics (multiple regression) might not relize
> that b corresponds to y, A to X, and x to b. So fitting y = X * b by
> least squares is sp.linalg.lstsq(X, y). I think the docstring should be
> more explicit on this.

http://docs.scipy.org/numpy/docs/numpy.linalg.linalg.lstsq/
http://docs.scipy.org/scipy/docs/scipy.linalg.basic.lstsq/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-Dev mailing list