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

标签 python pandas numpy linear-regression statsmodels

我使用 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()

This is the image of the results

最佳答案

根据docsRegressionResults 的一个实例已返回。

您可以在那里看到所有可用的属性。

也许您感兴趣:

params

The linear coefficients that minimize the least squares criterion. This is usually called Beta for the classical linear model.

示例:

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

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

相关文章:

python - 如何从Python对象中检查方法是否存在

python - 如何在 pandas 上读取下载的 sql 查询

python - 在 Pandas 数据框中的每一列上应用函数

python - 然后 Groupby 检查行匹配并计算该值的并发实例数

python - pandas 查找具有条件的元素的行+列名称

python - 将数据帧的切片添加到新列中的另一个数据帧

python - cv2.VideoWriter : Asks for a tuple as Size argument, 然后拒绝它

python - 如何合并/覆盖 Pandas 中的列

python - 当字符串中有多个逗号时,保留字符串中每个逗号后的第一个单词

python - 我可以在 np.mean() 中使用 str 吗?