Skip to main content
Add an explanation for compiling the table for LaTeX
Source Link
Max Ghenis
  • 193
  • 2
  • 11

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

To compile it in LaTeX instead of HTML, you can use: stargazer.render_latex()stargazer.render_latex()

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

To compile it in LaTeX instead of HTML, you can use: stargazer.render_latex()

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

To compile it in LaTeX instead of HTML, you can use: stargazer.render_latex()

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

There's also a nice looking LaTeX output, but I couldn't figure out how to renderTo compile it in JupyterLaTeX instead of HTML, you can use: stargazer.render_latex()

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

There's also a nice looking LaTeX output, but I couldn't figure out how to render it in Jupyter.

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

To compile it in LaTeX instead of HTML, you can use: stargazer.render_latex()

Source Link
Max Ghenis
  • 193
  • 2
  • 11

You can use the stargazer package (install with pip install stargazer).

From https://github.com/mwburke/stargazer/blob/master/examples.ipynb:

import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
from IPython.core.display import HTML

diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target

est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()

stargazer = Stargazer([est, est2])

HTML(stargazer.render_html())

enter image description here

There's also a nice looking LaTeX output, but I couldn't figure out how to render it in Jupyter.