从 OLS 回归结果中读取 coef 值
Reading coef value from OLS regression results
我使用 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()
根据docs, an instance of RegressionResults返回。
您可以在那里看到所有可用的属性。
也许你感兴趣:
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)
试试这个:
B0、B1、B2、B3 = modelo.params
我使用 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()
根据docs, an instance of RegressionResults返回。
您可以在那里看到所有可用的属性。
也许你感兴趣:
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)
试试这个:
B0、B1、B2、B3 = modelo.params