[SciPy-user] weighted least squares fit
Thu Aug 30 21:18:04 CDT 2007
On 30/08/2007, Wolfgang Kerzendorf <email@example.com> wrote:
> Is there a weighted least squares fit in scipy. As far as I have seen
> there's none.
> thanks in advance
You can get a weighted fit by simply scaling your coefficient matrix
and result vector:
If you want to find x making (Mx-b) as small as possible in the
least-squares sense, you can use scipy.linalg.lstsq. If you want to
weight row i by w[i], just multiply b[i] and M[i,:] by w[i].
If you want a more sophisticated linear least-squares solver, look at
ODR (which I don't know anything about). If you want nonlinear
least-squares (scipy.optimize.leastsq), the same trick works but you
need to put it in your objective function.
More information about the SciPy-user