1

Is it possible to perform multi-variate regression in Python using NumPy?

The documentation here suggests that it is, but I cannot find any more details on the topic.

3 Answers 3

3

Yes, download this ( http://www.scipy.org/Cookbook/OLS?action=AttachFile&do=get&target=ols.0.2.py ) from http://www.scipy.org/Cookbook/OLS

Or you can install R and a python-R link. R can do anything.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm currently using R, but I was considering making the calculation just python, for ease of sharing.
It doesn't work any longer (I changed it to conform to Python 3, so it run; but the very first test crashed Python interpreter with no error message). Anyone knows how to update it?
2

The webpage that you linked to mentions numpy.linalg.lstsq to find the vector x which minimizes |b - Ax|. Here is a little example of how it can be used:

First we setup some "random" data:

import numpy as np
c1,c2 = 5.0,2.0
x = np.arange(1,11)/10.0
y = c1*np.exp(-x)+c2*x
b = y + 0.01*max(y)*np.random.randn(len(y))
A = np.column_stack((np.exp(-x),x))
c,resid,rank,sigma = np.linalg.lstsq(A,b)
print(c)
# [ 4.96579654  2.03913202]

Comments

1

You might want to look into the scipy.optimize.leastsq function. It's rather complicated but I seem to remember that being the thing I would look to when I wanted to do a multivariate regression. (It's been a while so I could be misremembering)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.