6

我正在关注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()
4

1 回答 1

12

运算符部分所示,您可以在公式字符串中使用“-1”来删除截距项:

results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) - 1', data=dat).fit()
于 2016-04-04T18:37:14.683 回答