我是Stack Overflow的忠实粉丝,我确信我的问题将在这里得到解答。我使用Scipy做线性回归。但是在一组特定的输入中,我没有得到正确的输出。 (Python 2.5中,SciPy的0.10.1视窗7 32位)Linregress给出不正确的结果
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。
我错过了什么吗?帮帮我。
如果您将x设为numpy数组,它会有帮助吗? 'x = numpy.array([0,0,...])'不要忘记导入numpy :) – halex
@halex - 我试过了,但没有 - 它没有。 linregress同样处理numpy数组和pythonic数组。 – PKG