Skip to content

Instantly share code, notes, and snippets.

@sachinsdate
Created September 10, 2022 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachinsdate/e86ff6c8d68054bfda2fa31139c51e90 to your computer and use it in GitHub Desktop.
Save sachinsdate/e86ff6c8d68054bfda2fa31139c51e90 to your computer and use it in GitHub Desktop.
import pandas as pd
import statsmodels.formula.api as smf
#Load the US Census Bureau data into a Dataframe
df = pd.read_csv('us_census_bureau_acs_2015_2019_subset.csv', header=0)
#Construct the model's equation in Patsy syntax. Statsmodels will automatically add the intercept and so we don't explicitly specify it in the model's equation
reg_expr = 'Percent_Households_Below_Poverty_Level ~ Median_Age + Homeowner_Vacancy_Rate + Percent_Pop_25_And_Over_With_College_Or_Higher_Educ'
#Build and train the model and print the training summary
olsr_model = smf.ols(formula=reg_expr, data=df)
olsr_model_results = olsr_model.fit()
print(olsr_model_results.summary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment