[Numpy-discussion] Multiple Regression

Alexey Tigarev alexey.tigarev@gmail....
Thu Nov 12 17:38:25 CST 2009


Hi All!

I have implemented multiple regression in a following way:

def multipleRegression(x, y):
    """ Perform linear regression using least squares method.

    X - matrix containing inputs for observations,
    y - vector containing one of outputs for every observation """
    mulregLogger.debug("multipleRegression(x=%s, y=%s)" % (x, y))
    xt = transpose(x)
    a = dot(xt, x)     # A = xt * x
    b = dot(xt, y)     # B = xt * y
    try:
        return linalg.solve(a, b)
    except linalg.LinAlgError, lae:
        mulregLogger.warn("Singular matrix:\n%s" % (a))
        mulregLogger.warn(lae)
        mulregLogger.warn("Determinant: %f" % (linalg.det(a)))
        raise lae

Can you suggest me something to optimize it?

I am using it on large number of observations so it is common to have
"x" matrix of about 5000x20 and "y" vector of length 5000, and more.
I also have to run that multiple times for different "y" vectors and
same "x" matrix.

Thanks,
Alexey


More information about the NumPy-Discussion mailing list