# [Numpy-discussion] Multiple Linear Regression

dileep kunjaai dileepkunjaai@gmail....
Wed Mar 16 08:07:46 CDT 2011

```Thank you for your time and consideration.................

On Wed, Mar 16, 2011 at 5:17 PM, Angus McMorland <amcmorl@gmail.com> wrote:

> On 16 March 2011 02:53, dileep kunjaai <dileepkunjaai@gmail.com> wrote:
> > Dear sir,
> >  Can we do multiple linear regression(MLR)  in python.... is there any
> > inbuilt function for MLR
>
> Yes, you can use np.linalg.lstsq [1] for this.
> Here's a quick example:
>
> import numpy as np
> # model is y = b0.x0 + b1.x1 + b2.x2
> b = np.array([3.,2.,1.])
> noise = np.random.standard_normal(size=(10,3)) * 0.1
> bn = b[None] + noise
> x = np.random.standard_normal(size=(10,3))
> y = np.sum(bn * x, axis=1)
> be = np.linalg.lstsq(x,y)
>
> and be[0] should be close to the original b (3,2,1.).
>
> [1]
> http://docs.scipy.org/doc/numpy-1.4.x/reference/generated/numpy.linalg.lstsq.html
>
> > --
> > DILEEPKUMAR. R
> > J R F, IIT DELHI
> --
> AJC McMorland
> Post-doctoral research fellow
> Neurobiology, University of Pittsburgh
>

--
DILEEPKUMAR. R
J R F, IIT DELHI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110316/0c6aae5e/attachment.html
```