[SciPy-User] Why scipy supply a different result comparing with matlab when doing multi-linear regression analysis

Sturla Molden sturla@molden...
Mon Oct 19 12:56:01 CDT 2009

??? skrev:
> Hello!
> I have used scipy to solve a multi-linear regression problem, I used 
> the function lstsq in scipy.linalg.
> But, when I compared the result with using matlab, I found the 
> function regress in matlab gave me a very different result.

With arrays X and Y, multiple linear regression looks like this:

import numpy as np
import scipy
from scipy.linalg import qr, solve

x = np.vstack((np.ones(X.shape[1]),X)).T
q,r = qr(x, econ=True)
b = solve(r, (np.mat(Y) * np.mat(q)).T).ravel()

More information about the SciPy-User mailing list