我使用pandas和statsmodels进行线性回归。但是,我找不到任何可能的方法来阅读结果。结果会显示出来,但我需要使用coef值进行进一步的计算。有没有可能将coef值存储到新变量中?

import statsmodels.api as sm
import numpy
ones = numpy.ones(len(x[0]))
t = sm.add_constant(numpy.column_stack((x[0], ones)))
for m in x[1:]:
    t = sm.add_constant(numpy.column_stack((m, t)))
results = sm.OLS(y, t).fit()

python - 从OLS回归结果读取coef值-LMLPHP

最佳答案

根据docs,返回RegressionResults的实例。
您可以在那里看到所有可用的属性。
也许你感兴趣的是:
参数
使最小二乘准则最小化的线性系数这通常被称为经典线性模型的Beta。
例子:

model = sm.OLS(Y,X)
results = model.fit()
print(results.params)

关于python - 从OLS回归结果读取coef值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45314026/

10-15 06:00