相关疑难解决方法(0)

statsmodels:将多个回归模型的汇总打印在一起

在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_noconstantresults_withconstant打印出来.这应该是一个非常有用的功能,但我没有在statsmodels文档中找到任何关于此的说明.

编辑:我想到的回归表将是这样的,我想知道是否有现成的功能来做到这一点.

python pandas statsmodels

2
推荐指数
3
解决办法
2579
查看次数

标签 统计

pandas ×1

python ×1

statsmodels ×1