本文介绍了如何从statsmodels.api中提取回归系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 result = sm.OLS(gold_lookback, silver_lookback ).fit()

得到结果后,如何获得系数和常数?

After I get the result, how can I get the coefficient and the constant?

换句话说,如果y = ax + c如何获取值ac?

In other words, ify = ax + chow to get the values a and c?

推荐答案

您可以使用拟合模型的params属性来获取系数.

You can use the params property of a fitted model to get the coefficients.

例如,以下代码:

import statsmodels.api as sm
import numpy as np
np.random.seed(1)
X = sm.add_constant(np.arange(100))
y = np.dot(X, [1,2]) + np.random.normal(size=100)
result = sm.OLS(y, X).fit()
print(result.params)

将为您显示一个numpy数组[ 0.89516052 2.00334187]-分别为截距和斜率的估计值.

will print you a numpy array [ 0.89516052 2.00334187] - estimates of intercept and slope respectively.

如果需要更多信息,可以使用对象result.summary(),该对象包含3个带有模型描述的详细表.

If you want more information, you can use the object result.summary() that contains 3 detailed tables with model description.

这篇关于如何从statsmodels.api中提取回归系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:07