Multiple linear regression with python
Question: I would like to calculate multiple linear regression with python. I found this
code for simple linear regression

    
    
    import numpy as np
    
    from matplotlib.pyplot import *
    
    x = np.array([1, 2, 3, 4, 5])
    
    y = np.array([2, 3, 4, 4, 5])
    
    n = np.max(x.shape)    
    
    X = np.vstack([np.ones(n), x]).T
    
    
    a = np.linalg.lstsq(X, y)[0]
    

So, a is the coefficient, but I don't see what `[0]` means ?

And how can I change the code to obtain multiple linear regressions ?


Answer: to extend it to Multiple Linear Regression all you have to do is to create a
multi dimensional x instead of a one dimension x.

i.e.,

    
    
    x = np.array([[1, 2, 3,4,5], [4, 5, 6,7,8]], np.int32)
    

<http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html>

and with respect to a[0] that is called the intercept in a linear regression,
i.e,

y = a + bx + error, a[0] = a, a[1] = b

