So now I have:
def fit_line2(x, y):
X = sm.add_constant(x, prepend=True) #Add a column of ones to allow the calculation of the intercept
model = sm.OLS(y, X,missing='drop').fit()
"""Return slope, intercept of best fit line."""
X = sm.add_constant(x)
return modelAnd:
model=fit_line2(merged2[:-1].lastqu,merged2[:-1].Units)
print fit.summary()But I cannot get
yrahead2=model.predict(merged2.lastqu[-1:]) or any variant to give me a prediction? Note that the pd.ols uses the same merged2.lastqu[-1:] to grab the data I want to 'predict" from, no matter what I put into the () for predict I'm not having any joy. It seems statsmodels wants something specific in the () other than a pandas DF cell I even tried to just put a number eg 2696 there but still nothing... My current error is
----> 3 yrahead2=model.predict(merged2.lastqu[-1:])
/usr/lib/pymodules/python2.7/statsmodels/base/model.pyc in predict(self, exog, transform, *args, **kwargs)
1004 exog = np.atleast_2d(exog) # needed in count model shape[1]
1005
-> 1006 return self.model.predict(self.params, exog, *args, **kwargs)
1007
1008
/usr/lib/pymodules/python2.7/statsmodels/regression/linear_model.pyc in predict(self, params, exog)
253 if exog is None:
254 exog = self.exog
--> 255 return np.dot(exog, params)
256
257 class GLS(RegressionModel):
ValueError: objects are not aligned
> /usr/lib/pymodules/python2.7/statsmodels/regression/linear_model.py(255)predict()
254 exog = self.exog
--> 255 return np.dot(exog, params)
256 ValueError Traceback (most recent call last) <ipython-input-130-2610639fcd9a> in <module>() 1 #projqu=merged2.lastqu[-1:].get_value(0) 2 #print model.params ----> 3 yrahead2=model.predict(merged2.lastqu[-1:].values) 4 model
/usr/lib/pymodules/python2.7/statsmodels/base/model.pyc in predict(self, exog, transform, *args, **kwargs) 1004 exog = np.atleast_2d(exog) # needed in count model shape[1] 1005 -> 1006 return self.model.predict(self.params, exog, *args, **kwargs) 1007 1008 /usr/lib/pymodules/python2.7/statsmodels/regression/linear_model.pyc in predict(self, params, exog) 253 if exog is None: 254 exog = self.exog --> 255 return np.dot(exog, params) 256 257 class GLS(RegressionModel): ValueError: objects are not aligned
> /usr/lib/pymodules/python2.7/statsmodels/regression/linear_model.py(255)predict() 254 exog = self.exog --> 255 return np.dot(exog, params) 256