Linear regression in NumPy

J

Jianzhong Liu

Hello, Guys,

I have a question about the linear_least_squares in Numpy.

My linear_least_squares cannot give me the results.

I use Numpy1.0. The newest version. So I checked online and get your
guys some examples.

I did like this.

[john@crux 77] ~ >> py
Python 2.4.3 (#1, May 18 2006, 07:40:45)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
from Numeric import *
from LinearAlgebra import linear_least_squares
from Matrix import *
y = Matrix([[1], [2], [4]])
x = Matrix([[1, 1], [1, 2], [1, 3]])
print y
Matrix([[1],
[2],
[4]])Matrix([[1, 1],
[1, 2],
[1, 3]])
Here my Numpy stops. and never give me a result. THis is the problem of
Numpy or sth wrong.

Can you guys give me a LinearAlgebra.py so that I can have a try?

Thanks,

John
 
J

Jon

I have a question about the linear_least_squares in Numpy.

Not quite sure what is going on, it looks like there could be some
confusion as to linear_least_squares is expecting as an argument of
some Numeric arrays and what you are supplying (a Matrix) is perhaps
not close enough to being the same thing.

Up-to-date versions for all this are all in "numpy" nowadays and the
numpy mailing list is perhaps a better place to ask:
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Anyway, I've pasted in an example using Numeric and LinearAlgebra,
which you seem to have on your system. They still work fine. Not sure
what the "Matrix" package is that you are using?

HTH,

Jon

example:

C:\>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
from Numeric import *
from LinearAlgebra import linear_least_squares
a=array( [[1, 1], [1, 2], [1, 3]] )
y=array( [ 1,2,4] ) # note 1 D
a
array([[1, 1],
[1, 2],
[1, 3]])
y array([1, 2, 4])
linear_least_squares(a,y)
(array([-0.66666667, 1.5 ]), array([ 0.16666667]), 2, array([
4.07914333, 0.60049122]))
# Is this what you expect as output???

Jianzhong said:
Hello, Guys,

I have a question about the linear_least_squares in Numpy.

My linear_least_squares cannot give me the results.

I use Numpy1.0. The newest version. So I checked online and get your
guys some examples.

I did like this.

[john@crux 77] ~ >> py
Python 2.4.3 (#1, May 18 2006, 07:40:45)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
from Numeric import *
from LinearAlgebra import linear_least_squares
from Matrix import *
y = Matrix([[1], [2], [4]])
x = Matrix([[1, 1], [1, 2], [1, 3]])
print y
Matrix([[1],
[2],
[4]])
Matrix([[1, 1],
[1, 2],
[1, 3]])
Here my Numpy stops. and never give me a result. THis is the problem of
Numpy or sth wrong.

Can you guys give me a LinearAlgebra.py so that I can have a try?

Thanks,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top