Fit and diagnose regression models with statsmodels
8 steps · about 2 h 35 min · Intermediate
- Fit your first statsmodels regression (tutorial, statsmodels, 15 min)
See the full path from loading data to a printed summary table before looking at any detail.
- Describe the model with a formula (tutorial, statsmodels, 20 min)
Formulas make categorical terms, interactions and transformations explicit and easy to change.
- Read the OLS summary table (tutorial, statsmodels, 25 min)
Learn what coefficients, standard errors, t-tests and R-squared each tell you, and what they cannot.
- Check the fit with residual plots (tutorial, statsmodels, 20 min)
Plots of residuals and partial regressions reveal curvature and outliers that the summary hides.
- Run formal diagnostic tests (tutorial, statsmodels, 20 min)
Tests for normality, unequal variance and influence turn visual hunches into documented checks.
- Use robust standard errors when variance is uneven (reference, statsmodels, 15 min)
Heteroskedasticity-robust errors keep confidence intervals honest without changing the coefficients.
- Report predictions with intervals (tutorial, statsmodels, 15 min)
A prediction is only useful with its uncertainty; separate the interval for the mean from that for a new case.
- Extend to binary outcomes with a GLM (tutorial, statsmodels, 25 min)
When the outcome is yes or no, a logistic GLM replaces OLS while keeping the same formula workflow.