Skip to content
Tutorials Center
My learning

Topics

Statsmodels Tutorial

Learn Statsmodels step by step: 28 lessons in 10 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

First Steps

  1. 1 What Is Statsmodels? Meet Statsmodels, the Python library for statistical models, tests and time series. See what it does, how it differs from scikit-learn, and run your first model.
  2. 2 Your First OLS Model Fit ordinary least squares in Statsmodels with arrays and DataFrames, read the coefficients, make predictions and plot the fitted line, step by step.
  3. 3 Reading the Summary Table Learn to read every part of the Statsmodels OLS summary: R-squared, F-statistic, AIC, coefficients, p-values, Omnibus, Durbin-Watson and Condition Number.

Linear Regression in Depth

  1. 4 Formulas and Patsy Write regression models as formulas like y ~ x1 + np.log(x2) in Statsmodels. Learn the Patsy operators, transformations, the no-intercept form and how to inspect design matrices.
  2. 5 Categorical Variables and Interactions Add categories to regression with C(), choose the reference level, read dummy coefficients and model interactions between a category and a number, with runnable examples.
  3. 6 Weighted and Robust Regression Handle unequal variance and outliers in Statsmodels with WLS, GLS, robust standard errors (HC3, HAC) and RLM. Learn which tool fixes which assumption failure.
  4. 7 Regularized Regression Shrink coefficients with ridge, lasso and elastic net in Statsmodels using fit_regularized. See how the penalty changes estimates and why inference needs care.

Diagnostics

  1. 8 Residual Diagnostics Check linearity, constant variance, normality and independence of OLS residuals in Statsmodels with plots and tests: Breusch-Pagan, Jarque-Bera, Q-Q plots, RESET and Durbin-Watson.
  2. 9 Influence and Outliers Find outliers and influential points in OLS with Statsmodels: leverage, studentized residuals, Cook's distance, DFFITS and influence plots, and decide what to do with them.
  3. 10 Multicollinearity and VIF Detect correlated predictors with the variance inflation factor in Statsmodels, see how they inflate standard errors, and fix the problem with dropping, combining or ridge.

Hypothesis Testing

  1. 11 Classical Tests and Power Run t-tests, z-tests, proportion tests and confidence intervals with statsmodels.stats, then plan sample size with power analysis for t-tests and proportions.
  2. 12 ANOVA and Multiple Testing Compare several groups with one-way and two-way ANOVA in Statsmodels, run Tukey HSD post-hoc tests, and control false positives with Bonferroni, Holm and FDR corrections.

Generalized Linear Models

  1. 13 Logistic and Probit Regression Model yes/no outcomes with Logit and Probit in Statsmodels. Read log-odds, odds ratios and marginal effects, predict probabilities and judge classification accuracy.
  2. 14 Count Models Model counts such as visits, claims or defects with Poisson and negative binomial regression in Statsmodels. Handle overdispersion, exposure offsets and excess zeros.
  3. 15 GLM Families and Links Understand generalized linear models in Statsmodels: pick a family and link for the outcome, fit Gaussian, Binomial, Poisson and Gamma GLMs, and read deviance and residuals.

Time Series

  1. 16 Time Series Basics Learn the building blocks of time series in Statsmodels: trend and seasonality decomposition, autocorrelation (ACF, PACF), stationarity and the ADF test, and differencing.
  2. 17 ARIMA Models Fit AR, MA and ARIMA models with Statsmodels, choose orders from ACF/PACF and AIC, check residuals with Ljung-Box, and produce forecasts with confidence intervals.
  3. 18 Exponential Smoothing and SARIMAX Forecast seasonal data with Holt-Winters exponential smoothing and SARIMAX in Statsmodels, add exogenous regressors, compare models on a holdout and read the forecasts.

Other Models

  1. 19 Mixed-Effects Models Model grouped or repeated data with mixed-effects models in Statsmodels. Fit random intercepts and slopes with MixedLM, read variance components and compare with plain OLS.
  2. 20 Quantile Regression Model the median and other quantiles with QuantReg in Statsmodels. See why OLS misses changing spread, fit several quantile lines and use them as prediction bands.
  3. 21 LOWESS and KDE Use nonparametric tools in Statsmodels: LOWESS to draw a flexible trend line without a formula, and kernel density estimation to estimate a distribution shape.

Pitfalls and Production

  1. 22 Pitfalls and Debugging Avoid the usual Statsmodels mistakes: missing intercept, NaN and dtype errors, wrong column order, extrapolation, causal claims, p-hacking and convergence warnings, with fixes.
  2. 23 Predict, Save and Deploy Move a Statsmodels model into production: predict with intervals, shrink and pickle results, reload them, validate inputs, test on a holdout and wrap everything in a function.

Projects

  1. 24 Project: House Price Model Build a complete regression workflow in Statsmodels: explore the data, fit and improve an OLS model, run diagnostics, use robust errors and validate predictions on a holdout.
  2. 25 Project: Customer Churn Analyze why customers leave using logistic regression in Statsmodels: build features, read odds ratios and marginal effects, pick a threshold and evaluate with a confusion matrix.
  3. 26 Project: Sales Forecast Forecast monthly sales end to end with Statsmodels: decompose the series, build baselines, fit Holt-Winters and SARIMAX, compare with rolling-origin validation and report intervals.

Practice and Review

  1. 27 Practice Exercises Test your Statsmodels skills with eight hands-on exercises on OLS, formulas, diagnostics, logit, counts, tests and forecasting. Each task has a runnable solution to compare against.
  2. 28 Statsmodels Cheat Sheet A one-page Statsmodels reference: imports, model classes, formula syntax, results attributes, diagnostics, GLM families, time-series tools and a model-choice guide.