使用来自statsmodels.formula.api的ols - 如何删除常量项?

den*_*ufa 3 python regression numpy statsmodels patsy

我在statsmodels教程中关注第一个例子:

http://statsmodels.sourceforge.net/devel/

如何指定不在ols中使用常量项进行线性拟合?

# Fit regression model (using the natural log of one of the regressors)
results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()
Run Code Online (Sandbox Code Playgroud)

ely*_*ely 8

操作符一节所示,您可以在公式字符串中使用"-1"来删除截距项:

results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) - 1', data=dat).fit()
Run Code Online (Sandbox Code Playgroud)