NumPy中的线性回归 [英] Linear regression in NumPy

查看:95
本文介绍了NumPy中的线性回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,伙计们,


我对Numpy中的linear_least_squares有疑问。


我的linear_least_squares无法给我结果。


我使用的是Numpy1.0。最新版本。所以我在网上查了一下你的

家伙的一些例子。


我喜欢这样。


[约翰@crux 77]〜> py

Python 2.4.3(#1,2006年5月18日,07:40:45)

[GCC 3.3.3(cygwin special) )] on cygwin

输入help,copyright,credit等等。或许可证或欲获得更多信息。


>>来自数字导入*
来自LinearAlgebra import linear_least_squares y = Matrix([[1],[2],[4]])
x =矩阵([[1,1],[1,2],[ 1,3]])
打印y



矩阵([[1],

[2],

[4]])


>> x



矩阵([[1,1],

[1,2] ],

[1,3]])


> ;> print linear_least_squares(x,y)



这里我的Numpy停止了。永远不要给我一个结果。这是

Numpy或者是错误的问题。


你能给我一个LinearAlgebra.py以便我可以尝试一下吗?

谢谢,


John

解决方案

I对Numpy中的linear_least_squares有疑问。


不太确定发生了什么,看起来可能会有一些

混乱,因为linear_least_squares正在期待作为一个参数

一些数字数组和你提供的东西(一个矩阵)可能是

不够接近同一个东西。

所有这些的最新版本都在numpy中。现在和

numpy邮件列表可能是一个更好的地方:
http://projects.scipy.org/mailman/li...mpy-discussion


无论如何,我是'使用Numeric和LinearAlgebra粘贴在一个示例中,

,您似乎在您的系统上。他们仍然工作正常。不确定

什么是矩阵你正在使用的包装是什么?


HTH,


Jon


例如:


C:\> python

Python 2.4.3(#69,2006年3月29日,17:35:34)[MSC v.1310 32 bit (英特尔)]

on win32

输入help,copyright,credit等等。或许可证或欲获得更多信息。


>>来自数字导入*
来自LinearAlgebra import linear_least_squares
a =数组([[1,1],[1,2],[1,3]])
y =数组([1,2,4])#note 1 D
a



数组([[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]))

< blockquote class =post_quotes>


>>>



#这是你期望的输出吗?


Jianzhong Liu写道:


您好,伙计们,


我对Numpy中的linear_least_squares有疑问。

我的linear_least_squares无法给我结果。


我使用的是Numpy1.0。最新版本。所以我在网上查了一下你的

家伙的一些例子。


我喜欢这样。


[约翰@crux 77]〜> py

Python 2.4.3(#1,2006年5月18日,07:40:45)

[GCC 3.3.3(cygwin special) )] on cygwin

输入help,copyright,credit等等。或许可证或欲获得更多信息。


>来自数字导入*
来自LinearAlgebra import linear_least_squares
来自Matrix import *
y =矩阵([[1],[2],[4]])
x =矩阵([[1,1],[1,2],[1,3]])
打印y



矩阵([[1],

[2],

[ 4]])


> x



矩阵([[1,1],

[1,2],

[1,3]])


> print linear_least_squares(x,y)



这里我的Numpy停止了。永远不要给我一个结果。这是

Numpy或者是错误的问题。


你能给我一个LinearAlgebra.py以便我可以尝试一下吗?

谢谢,


John


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]])

>>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

解决方案

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
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 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
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]])

>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


这篇关于NumPy中的线性回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆