472,352 Members | 1,580 Online

# Linear regression in NumPy

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
>>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]])
>>x
Matrix([[1, 1],
[1, 2],
[1, 3]])
>>print linear_least_squares(x, y)
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

Dec 5 '06 #1
1 7347
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/li...mpy-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
>>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 Liu wrote:
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
>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]])
>x
Matrix([[1, 1],
[1, 2],
[1, 3]])
>print linear_least_squares(x, y)

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
Dec 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 15 by: nikie | last post by: I'm a little bit stuck with NumPy here, and neither the docs nor trial&error seems to lead me anywhere: I've got a set of data points... 3 by: sql guy123 | last post by: This is a real challenge. I hope someone is smart enough to know how to do this. I have a table TABLE1 1 by: wirecom | last post by: Hi all, I am seeking a module that will do the equivalent of linear regression in 3D to yield a best fit a plane through a set of points (X1, Y1,... 1 by: zRaVeNk | last post by: anyone help me with linear regression in visual basic here's what i'm working with: screenshot 1 by: Nod Lee | last post by: Hi all Is there any tools/objects from Microsoft that I can use to perform linear regression in webform and generate the results into a graph? ... 1 by: Michael O'Brien | last post by: Hola~ I have a large array of points (over a million). I would like to multiply each point in the array by a 4x4 matrix. I keep thinking there... 3 by: ntuyen01 | last post by: Hi All, Does anyone has examples for Linear Regression formula using c#. Or any good third party software create this. Thanks in advance... 3 by: jivelasquezt | last post by: Hi all, I'm new to this group so I don't know if this question has been posted before, but does anyone knows about linear/integer programming... 7 by: PlsHelp | last post by: Hi every1,this is my 1st time using this forum....pls can any1 tell me how to create a code in VB that can do LINEAR REGRESSION in excel.....i'm not... 0 by: drfish | last post by: Hi, I'm a complete novice when it comes to VB so need some help. I would like a macro that performs linear regression for different cell ranges... 1 by: Kemmylinns12 | last post by: Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and... 0 by: Naresh1 | last post by: What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge... 0 by: jalbright99669 | last post by: Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made... 0 by: antdb | last post by: Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was... 2 by: Matthew3360 | last post by: Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it... 0 by: AndyPSV | last post by: HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable... 0 by: WisdomUfot | last post by: It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific... 0 by: Oralloy | last post by: Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the... 0 by: Rahul1995seven | last post by: Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...