Reputation: 615
x=range(100)
y=sin(x)
result=sm.OLS(x,y).fit()
result.predict(x)
Gives:
ValueError: matrices are not aligned
This is very simple code, not sure why it's not working? I searched lots of forums but could not find exact solution.
Upvotes: 0
Views: 297
Reputation: 22897
quick answer:
I think you want x and y reversed result=sm.OLS(y, x).fit()
The dependent variable (y
) comes first, and then the array of explanatory variables (x
).
The call to predict works with statsmodels master, but maybe you need a 2-D x
in an older version:
result.predict(x[:,None])
to make the explanatory variable into a column_array. I don't remember when this was changed for 1-D x.)
Note also, that there is no constant/intercept added automatically when we don't use the formula interface.
The predict for the sample or training data can also be accessed through results.fittedvalues
.
Upvotes: 1