Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python statistics libraries compute descriptive statistics, run hypothesis tests, and fit statistical models to data. Some libraries specialize in one family of models, such as survival analysis, Bayesian inference, or time series forecasting. These libraries let analysts, researchers, and AI agents test hypotheses and fit models in Python.
Popularity
SciPy has the most monthly downloads in this comparison, at 389.6M, a count that covers all its scientific computing.
def _fit(self, fit_data, weights=None):
"""Fit the scipy kde while adding bw_adjust logic and version check."""
fit_kws = {"bw_method": self.bw_method}
if weights is not None:
fit_kws["weights"] = weights
kde = gaussian_kde(fit_data, **fit_kws)
kde.set_bandwidth(kde.factor * self.bw_adjust)
return kde
statsmodels
Estimates statistical models and runs hypothesis tests.
Downloads / mo
40.4M
Stars
11.8K
Last release
0.15.0
License
BSD-3-Clause
Strengths
Accepts R-style model formulas.Describe models with formulas against pandas DataFrames.
Fits Bayesian mixed-effects models.Estimate binomial and Poisson mixed models with Bayesian approximation methods.
Limitations
Missing data needs explicit handling.Set missing='raise' or clean missing values before fitting.
Array OLS omits automatic intercepts.Call add_constant when the model needs an intercept.
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf
# Load datadat = sm.datasets.get_rdataset("Guerry", "HistData").data
# Fit regression model (using the natural log of one of the regressors)results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()
# Inspect the resultsprint(results.summary())
import os
from cmdstanpy import cmdstan_path, CmdStanModel
# specify locations of Stan program file and datastan_file = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
data_file = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.data.json')
# instantiate a model; compiles the Stan program by defaultmodel = CmdStanModel(stan_file=stan_file)
# obtain a posterior sample from the model conditioned on the datafit = model.sample(chains=4, data=data_file)
def _fit_cph(features, outcomes, val_data, random_seed, **hyperparams):
"""Fit a linear Cox Proportional Hazards model to a given dataset.
Parameters
----------- features : pd.DataFrame
A pandas dataframe with rows corresponding to individual samples and
columns as covariates.
outcomes : pd.DataFrame
A pandas dataframe with columns 'time' and 'event'.
val_data : tuple
A tuple of the validation dataset features and outcomes of
'time' and 'event'.
random_seed : int
Controls the reproducibility of called functions.
hyperparams : Optional arguments
Options include:
- 'l2' : float, default=1e-3
Penalizer
Returns
----------- Trained instance of the Cox Proportional Hazards model.
"""
from lifelines import CoxPHFitter
data = outcomes.join(features)
penalizer = hyperparams.get('l2', 1e-3)
return CoxPHFitter(penalizer=penalizer).fit(data,
duration_col='time',
event_col='event')
import pmdarima as pm
from pmdarima.model_selection import train_test_split
# Load/split your datay = pm.datasets.load_wineind()
train, test = train_test_split(y, train_size=150)
# Fit your modelmodel = pm.auto_arima(train, seasonal=True, m=12)
def _fit(self, y, X, fh):
"""Fit to training data.
Parameters
---------- y : pd.Series
Target time series to which to fit the forecaster.
fh : int, list, np.array or ForecastingHorizon, optional (default=None)
The forecasters horizon with the steps ahead to predict.
X : pd.DataFrame, optional (default=None)
Exogenous variables are ignored
Returns
------- self : returns an instance of self.
"""
self._cur_y = y
self._cur_X = X
if X is not None:
X = X.loc[y.index]
# statsmodels >= 0.15 raises on out-of-sample prediction if the index # is not supported, e.g., an integer index not starting at 0, # so we pass a RangeIndex in this case. Predictions are re-indexed in _predict. y_fit = y
if pd.api.types.is_integer_dtype(y.index) and not isinstance(
y.index, pd.RangeIndex
):
y_fit = y.reset_index(drop=True)
if X is not None:
X = X.reset_index(drop=True)
self._forecaster = self._instantiate_model()
self._forecaster.fit(y_fit, X=X)
self._y_name = y.name
return self
FAQ
SciPy suits probability distributions, correlations, and statistical tests. statsmodels suits regression, time series, and survival models with inference. lifelines suits survival analysis. Prophet suits forecasts with trend and seasonality.
statsmodels estimates statistical models and runs hypothesis tests, with formula-based regression workflows. Its array-based OLS interface leaves the intercept out by default.
StatsForecast is a time series forecasting suite of statistical models, with automatic ARIMA and ETS model selection.
SciPy covers probability distributions, correlations, and statistical tests. statsmodels adds model estimation and formula-based regression.
Prophet forecasts time series with trend and seasonality components. Its default fit is a point estimate, with optional full Bayesian sampling through Stan.
For coding agents
Found your statistics library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.