Calculating PLS for Python

Is there a good library for calculating linear least squares OLS (Ordinary Least Squares) in python?

Thanks.

Edit:

Thanks for SciKits and Scipy. @ars: Could X be a matrix? Example:

y(1) = a(1)*x(11) + a(2)*x(12) + a(3)*x(13) y(2) = a(1)*x(21) + a(2)*x(22) + a(3)*x(23) ........................................... y(n) = a(1)*x(n1) = a(2)*x(n2) + a(3)*x(n3) 

Then how to pass parameters for Y and X matrices in your example?

Also, I don't have much experience in algebra, I would appreciate it if you guys could tell me a good tutorial on such issues.

Thank you very much.

+4
source share
2 answers

Try the statsmodels package. Here is a quick example:

 import pylab import numpy as np import statsmodels.api as sm x = np.arange(-10, 10) y = 2*x + np.random.normal(size=len(x)) # model matrix with intercept X = sm.add_constant(x) # least squares fit model = sm.OLS(y, X) fit = model.fit() print fit.summary() pylab.scatter(x, y) pylab.plot(x, fit.fittedvalues) 

Update In response to an updated question, yes, it works with matrices. Note that the code above has data x in the form of an array, but we are building the matrix x (capital X) to go to OLS . The add_constant function simply builds a matrix with the first column initialized to units for interception. In your case, you just pass your matrix x without requiring this intermediate step, and it will work.

+9
source

Have you looked at SciPy? I do not know if this is so, but I would have thought that it would be.

+4
source

All Articles