statsmodels Documentation
The official docs for statsmodels, the Python library for estimating statistical models, running hypothesis tests and reading full regression output with standard errors, p-values and confidence intervals. It is where you go when the question is not only "what does the model predict" but "how sure are we, and why".
11.7k (statsmodels/statsmodels)
GitHub · Sept 2026
0.15.0 (August 2026)
statsmodels.org · Sept 2026
Modified BSD (3-clause)
statsmodels.org · Sept 2026
Guide
AI & Machine Learning
statsmodels
Two to three weeks for regression and tests
Intermediate
Free
What statsmodels is
In its own words, statsmodels "provides classes and functions for estimating statistical models, running hypothesis tests, and exploring data in Python". Each estimator comes with an extensive list of result statistics, and the project states that results are tested against existing statistical packages to check they are correct. It is released under the open source Modified BSD (3-clause) licence.
Why a data science learner needs it
scikit-learn is built for prediction. statsmodels is built for inference: estimating an effect, putting an interval around it and testing whether it could be noise. When a manager asks "did the price change actually increase sales?", a summary() table from statsmodels with coefficients, standard errors, p-values and confidence intervals is what you need to reason about the answer.
You can specify models with R-style formulas on a pandas DataFrame, for example smf.ols('sales ~ price + C(region)', data=df).fit(), which keeps your code close to how you would describe the model in words.
What the docs cover
The front page links to four areas: Getting started, the User Guide, Examples (applied notebooks on real datasets) and the API Reference. Inside the User Guide, the parts most learners need first are:
- Background pages: "endog, exog, what's that?", fitting models with formulas, and Pitfalls
- Linear regression, generalised linear models (logistic and Poisson regression) and ANOVA
- The Statistics section: t-tests, tests for proportions, multiple testing corrections and diagnostics
- Contingency tables
Later you can move to time series analysis, mixed effects models, survival analysis and nonparametric methods, all documented in the same guide.
How long it takes and prerequisites
Plan two to three weeks to become comfortable with regression output and the common tests, working through the Examples notebooks. You need pandas, NumPy and introductory statistics: means, variance, distributions, hypothesis tests and what a p-value is. The docs explain the library, not the statistics from scratch.
Free or paid?
Free and open source. Install with python -m pip install statsmodels.
Common questions
statsmodels or scikit-learn? Use scikit-learn when you care about predictive accuracy on new data, statsmodels when you need to explain and quantify effects. Many projects use both.
Why does my regression have no intercept? With arrays rather than formulas you must add one yourself with sm.add_constant. The Pitfalls page covers this and similar traps.
Best for: learners who know the basics of statistics and want to run and interpret real models in Python.
Ready to start?
Opens on statsmodels in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.