这是我正在做的事情:
$ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>> import statsmodels.api as sm
>>> statsmodels.__version__
'0.5.0'
>>> import numpy
>>> y = numpy.array([1,2,3,4,5,6,7,8,9])
>>> X = numpy.array([1,1,2,2,3,3,4,4,5])
>>> res_ols = sm.OLS(y, X).fit()
>>> res_ols.params
array([ 1.82352941])
我期待一个包含两个元素的数组?!? 截距和斜率系数?
最佳答案
试试这个:
X = sm.add_constant(X)
sm.OLS(y,X)
如 documentation :
An intercept is not included by default and should be added by the user
关于python - 为什么我只能从 statsmodels OLS 拟合中获得一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701484/