更新时间:2023-12-02 13:51:34
您可以使用拟合模型的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.