Wednesday, 15 September 2010

python statsmodels.predict does not work -



python statsmodels.predict does not work -

x=range(100) y=sin(x) result=sm.ols(x,y).fit() result.predict(x)

gives:

valueerror: matrices not aligned

this simple code, not sure why it's not working? searched lots of forums not find exact solution.

quick answer:

i think want x , y reversed result=sm.ols(y, x).fit() dependent variable (y) comes first, , array of explanatory variables (x).

the phone call predict works statsmodels master, maybe need 2-d x in older version:

result.predict(x[:,none])

to create explanatory variable column_array. don't remember when changed 1-d x.)

note also, there no constant/intercept added automatically when don't utilize formula interface.

the predict sample or training info can accessed through results.fittedvalues.

python statsmodels

No comments:

Post a Comment