Re: [SciPy-User] Multivariate linear (bilinear) fit (Charles R Harris)
Indeed, in statistics it's a linear model. Try r2py. R's really good in linear models and will give you additional information on significance tests. Best, Jus On Apr 20, 2017 02:14, <scipy-user-request@python.org> wrote: Send SciPy-User mailing list submissions to scipy-user@python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/scipy-user or, via email, send a message with subject or body 'help' to scipy-user-request@python.org You can reach the person managing the list at scipy-user-owner@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of SciPy-User digest..." Today's Topics: 1. Re: Multivariate linear (bilinear) fit (Charles R Harris) ---------------------------------------------------------------------- Message: 1 Date: Wed, 19 Apr 2017 18:12:49 -0600 From: Charles R Harris <charlesr.harris@gmail.com> To: SciPy Users List <scipy-user@python.org> Subject: Re: [SciPy-User] Multivariate linear (bilinear) fit Message-ID: <CAB6mnxKo15OS45qnj6TvXxoea2fQcre3og3vxCjDFNDEH=Lakg@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Wed, Apr 19, 2017 at 4:38 PM, Joe Kington <joferkington@gmail.com> wrote:
They're relatively recent additions, but numpy.polynomial.polyvander2d and numpy.polynomial.polyval2d should also do what you want, unless I'm misunderstanding the problem.
https://docs.scipy.org/doc/numpy/reference/generated/ numpy.polynomial.polynomial.polyvander2d.html#numpy.polynomial.polynomial. polyvander2d https://docs.scipy.org/doc/numpy/reference/generated/ numpy.polynomial.polynomial.polyval2d.html#numpy.polynomial.polynomial. polyval2d
You can also do things like (you could generalize this to N-dimensions, as well):
def polyfit2d(x, y, z, order=3): ncols = (order + 1)**2 G = np.zeros((x.size, ncols)) ij = itertools.product(range(order+1), range(order+1)) for k, (i,j) in enumerate(ij): G[:,k] = x**i * y**j m, _, _, _ = np.linalg.lstsq(G, z) return m def polyval2d(x, y, m): order = int(np.sqrt(len(m))) - 1 ij = itertools.product(range(order+1), range(order+1)) z = np.zeros_like(x) for a, (i,j) in zip(m, ij): z += a * x**i * y**j return z
I think the "bilinear" is a mistake, as bilinear usually means terms of degree two. AFAICT, this question is just about multivariate linear fits only <snip> Chuck
participants (1)
-
Justus Schwabedal