XUTADO
XUTADO

Reputation: 153

Python: OLS Regression does not generate intercept

Can someone please tell me where I'm missing as the summary output does not provide constant at all though I have explicitly called it out? My df is 6212 rows × 64 columns. Thanks much.

import statsmodels.api as sm   
from statsmodels.api import add_constant

y1 = df.ix[:,-1:]

x1 = df.ix[:,16:-1]
x1 = add_constant(x1)

model1  = sm.OLS(y1 , x1 ).fit()
model1.summary()

Upvotes: 1

Views: 425

Answers (1)

bbkglb
bbkglb

Reputation: 769

Check your data to see if it already has a column with variance zero. add_constant() will not, by default, add a constant column to your dataset if it already has a zero-variance column; you should explicitly tell it to add the constant even if a zero-variance column exists:

x1 = add_constant(x1, has_constant = 'add')

You can read more about different options for the has_constant argument here: http://statsmodels.sourceforge.net/stable/generated/statsmodels.tsa.tsatools.add_constant.html

Upvotes: 1

Related Questions