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)
如操作符一节所示,您可以在公式字符串中使用"-1"来删除截距项:
results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) - 1', data=dat).fit()
Run Code Online (Sandbox Code Playgroud)