Reputation: 941
This problem originally occurred with real data, but it can be replicated with sample code from the statsmodels website (http://www.statsmodels.org/devel/generated/statsmodels.regression.linear_model.OLS.html)
import statsmodels.api as sm
y = [1,3,4,5,2,3,4]
x = range(1,8)
# x = sm.add_constant(x) # including this line makes no difference
model = sm.OLS.fit(y,x)
Here's the traceback:
File "rec.py", line 131, in test2
model = sm.OLS.fit(y,x)
File "C:\Python36\lib\site-packages\statsmodels\regression\linear_model.py", line 302, in fit
if self._df_model is None:
AttributeError: 'list' object has no attribute '_df_model'
No idea what to make of this or how to resolve it. It almost seems like I accidentally triggered some bad internal statsmodels state, especially because previously I had this basic call working on real data (with only a couple of feature columns, stored in a pandas dataframe)
Upvotes: 1
Views: 975
Reputation: 7402
remove from sm.OLS(Y,X) -> fit , this works, you dont put fit method where it needed
import statsmodels.api as sm
Y = [1,3,4,5,2,3,4]
X = range(1,8)
X = sm.add_constant(X)
model = sm.OLS(Y,X)
results = model.fit()
Upvotes: 2