2

我是 Stack Overflow 的忠实粉丝,我相信我的问题会在这里得到解答。我正在使用 Scipy 进行线性回归。但是在一组特定的输入中,我没有得到正确的输出。(Python 2.5、SciPy 0.10.1 Windows 7 32 位)

from scipy.stats import linregress
from numpy import arange
x = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,2,0,0,2]
y = arange(1,36)
s,i,r,p,st = linregress(x,y)

这里 s 的值为 9.241573,但 Excel 报告斜率为 0.026。

我错过了什么吗?帮助。

4

1 回答 1

5

您似乎有错误的论点:

s,i,r,p,st = linregress(y,x)

s = 0.026330532212885151. Excel 和 Scipy 的参数顺序相反。

于 2012-09-01T23:14:58.967 回答