Fit and diagnose regression models with statsmodels

8 steps · about 2 h 35 min · Intermediate

  1. 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.

  2. Describe the model with a formula (tutorial, statsmodels, 20 min)

    Formulas make categorical terms, interactions and transformations explicit and easy to change.

  3. 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.

  4. Check the fit with residual plots (tutorial, statsmodels, 20 min)

    Plots of residuals and partial regressions reveal curvature and outliers that the summary hides.

  5. Run formal diagnostic tests (tutorial, statsmodels, 20 min)

    Tests for normality, unequal variance and influence turn visual hunches into documented checks.

  6. Use robust standard errors when variance is uneven (reference, statsmodels, 15 min)

    Heteroskedasticity-robust errors keep confidence intervals honest without changing the coefficients.

  7. 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.

  8. 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.