statsmodels摘要为乳胶 [英] statsmodels summary to latex

查看:78
本文介绍了statsmodels摘要为乳胶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是乳胶的新手,我想将 statsmodels (python-package)摘要导入我的乳胶报告.我发现可以使用以下方法将摘要转换为乳胶表格:

I'm a newbie to latex and I want to import a statsmodels(python-package) summary to my report in latex. I found that it's possible to transform a summary into a latex tabular with the following method: latex_as_tabular. Until now everything is working. Now I have to store the tabular, but I don't really understand how this works.

我想我必须使用以下命令:

I suppose I have to use the following commands:

x_values=sm.add_constant(x_values)
model=sm.OLS(y_values, x_values)
results=model.fit()
tbl=results.summary(xname=['b,'a'],yname='y')
with open('c:/temp/temp.tex','w') as fh:
    fh.write( tbl.as_latex_tabular() )

此代码直到现在都无法使用.在大多数情况下,控制台会显示错误:此映射中不存在tex-file或不允许该文件.我真的不明白我该怎么办.有人可以帮我吗?

this code doesn't work until now. most of the times the console gives the error: tex-file doesn't exists or not permitted in this map. I don't really understand what I have to do here. Could someone please help me with this ?

推荐答案

这似乎是一种误解.您可以通过来一张一张地转换其表每个表的table.as_latex_tabular() .

That seems to be a misunderstanding. You can either convert a whole summary into latex via summary.as_latex() or convert its tables one by one by calling table.as_latex_tabular() for each table.

以下示例代码摘自statsmodels文档.请注意,您不能在summary对象上调用as_latex_tabular.

The following example code is taken from statsmodels documentation. Note that you cannot call as_latex_tabular on a summary object.

import numpy as np
import statsmodels.api as sm

nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)

X = sm.add_constant(X)
y = np.dot(X, beta) + e

model = sm.OLS(y, X)
results = model.fit()

# do either
print(results.summary().as_latex())

# alternatively
for table in results.summary().tables:
    print(table.as_latex_tabular())

这篇关于statsmodels摘要为乳胶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆