简体   繁体   English

使用 statsmodels 在多元线性回归中添加常量

[英]Adding a constant in Multiple Linear Regression using statsmodels

How can I add a constant to my statsmodels regression.如何向我的 statsmodels 回归添加常量。

As of now, the model is like this:截至目前,模型是这样的:

model = sm.OLS(y,x).fit()

From the documentation for OLS :来自OLS的文档:

exog : A nobs xk array where nobs is the number of observations and k is the number of regressors. exog :一个 nobs xk 数组,其中 nobs 是观察的数量,k 是回归量的数量。 An intercept is not included by default and should be added by the user.默认情况下不包含拦截,应由用户添加。 See statsmodels.tools.add_constant.请参见 statsmodels.tools.add_constant。

X = sm.add_constant(x)
sm.OLS(y,X)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM