Skip to content

Instantly share code, notes, and snippets.

@yoki
Last active November 8, 2022 03:55
Show Gist options
  • Save yoki/ea6bfba0749d68b6635bd41169ab7ce0 to your computer and use it in GitHub Desktop.
Save yoki/ea6bfba0749d68b6635bd41169ab7ce0 to your computer and use it in GitHub Desktop.
Python Statistics
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment