[SciPy-User] Multivariate linear (bilinear) fit

Nathaniel Smith njs at pobox.com
Wed Apr 19 17:17:01 EDT 2017


On Tue, Apr 18, 2017 at 10:17 AM, Daniele Nicolodi <daniele at grinta.net> wrote:
> Hello,
>
> before I write my own, does SciPy come with a function for multivariate
> (often also called bilinear, in the case of two variables) linear fits?
>
> I would like to fit a function if the form:
>
>   y = c + p1 * x1 + p2 * x2 + ... + pn * xn
>
> which is a simple least squares problem, but I would like to avoid to
> write the code :-)

np.linalg.lstsq and scipy.linalg.lstsq handle both univariate and
multivariate problems. They're pretty bare-bones, though, and they
also compute the sum of squared residuals which can make them slow if
you don't need it and are solving lots of problems in a tight loop.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the SciPy-User mailing list