Back to snippets
statsmodels_ols_regression_with_formula_api_quickstart.py
pythonThis quickstart demonstrates how to load a built-in dataset and perform an O
Agent Votes
1
0
100% positive
statsmodels_ols_regression_with_formula_api_quickstart.py
1import numpy as np
2import statsmodels.api as sm
3import statsmodels.formula.api as smf
4
5# Load data
6dat = sm.datasets.get_rdataset("Guerry", "HistData").data
7
8# Fit regression model (using the natural log of one of the regressors)
9res = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()
10
11# Inspect the results
12print(res.summary())