python - 为什么 OLS 回归模型中除了第一个(截距)之外的所有系数都获得非常接近零(e^-17 或低)的值?

标签 python python-3.x linear-regression statsmodels

我使用 statsmodels 包在 python 中编写了以下代码,以创建 OLS 回归模型。我尝试了使用不同数据集的代码,并得到了除第一个(截距)系数外所有系数值都接近零的模型。代码可能有什么问题?

data1 = pandas.concat([Y, X], axis = 1)
dta = lagmat2ds(data1, mxlg, trim='both', dropex=1)
dtaown = sm.add_constant(dta[:, 0:(mxlg + 1)], prepend = False)
dtajoint = sm.add_constant(dta[:, 0:], prepend = False)
res2down = sm.OLS(dta[:, 0], dtaown).fit()
res2djoint = sm.OLS(dta[:, 0], dtajoint).fit()

Here the sm is statsmodels.api as sm and for sample testing you can consider the dataset sm.datasets.spector.

最佳答案

数据的结构方式 - 您正在建模 YY|lag Y|constant。请注意,OLS 文档 ( https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.html ) 指出 -

No constant is added by the model unless you are using formulas.

因此,您看到的第一个值不是截距,而是拟合 YY 的系数 - 将为 1.0

您可以尝试检查是否获得了合理的结果,即从预测变量中排除 Y,如下所示 -

res2down = sm.OLS(dta[:, 0], dtaown[:, 1:]).fit()

关于python - 为什么 OLS 回归模型中除了第一个(截距)之外的所有系数都获得非常接近零(e^-17 或低)的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54035907/

相关文章:

java - 无法使用 selenium webdriver 获取元素文本

python - 逆变换预测结果

python - pandas fillna 目前只能逐列填充dict/Series

python - 如果列表项以 '.' 开头,为什么 python3 不从列表创建文件夹?

python - 如何在Python中将视频分成4个相等的部分?

R:具有 N 个特征的线性回归

python - 无法满足的错误 : The following specifications were found to be in conflict: - pil -> python 2. 6* - python 3.6*

python - 打印或返回括号之间的字符串

linear-regression - 使用 PyMC3 进行基本贝叶斯线性回归预测

python - 如何在此图中绘制线性回归线?