在Python库中Statsmodels,您可以打印出回归结果print(results.summary()),如何在一个表中打印出多个回归的摘要,以便更好地进行比较?
线性回归,代码取自statsmodels文档:
nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([0.1, 10])
e = np.random.normal(size=nsample)
y = np.dot(X, beta) + e
model = sm.OLS(y, X)
results_noconstant = model.fit()
Run Code Online (Sandbox Code Playgroud)
然后我向模型添加一个常量并再次运行回归:
beta = np.array([1, 0.1, 10])
X = sm.add_constant(X)
y = np.dot(X, beta) + e
model = sm.OLS(y, X)
results_withconstant = model.fit()
Run Code Online (Sandbox Code Playgroud)
我想在一张桌子上看到摘要results_noconstant并results_withconstant打印出来.这应该是一个非常有用的功能,但我没有在statsmodels文档中找到任何关于此的说明.
编辑:我想到的回归表将是这样的,我想知道是否有现成的功能来做到这一点.