[Numpy-discussion] Multiple Regression
alexey.tigarev at gmail.com
Thu Nov 12 18:38:25 EST 2009
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
return linalg.solve(a, b)
except linalg.LinAlgError, lae:
mulregLogger.warn("Singular matrix:\n%s" % (a))
mulregLogger.warn("Determinant: %f" % (linalg.det(a)))
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.
More information about the NumPy-Discussion