GPU-accelerated statistical methods with an sklearn-style API.
Website & Documentation · English · 中文文档
- 🚀 Three backends: NumPy (CPU), CuPy (CUDA), and PyTorch (CUDA), with automatic device selection
- 🔧 sklearn-style estimators: familiar
fit/predict/scoremethods and parameter conventions - 📊 GLM + robust + quantile + Cox: Gaussian and non-Gaussian regression, robust losses, quantile regression, and survival analysis
- 🔥 Penalty framework: L1, L2, Elastic Net, SCAD, MCP, adaptive, and grouped penalties
- ⚡ Solver framework: exact, IRLS, Newton, L-BFGS, FISTA-family, proximal IRLS, proximal Newton, and ADMM implementations where supported
- 🧮 Inference: covariance, standard errors, hypothesis tests, confidence intervals, penalized sandwich/oracle inference where supported, debiased Lasso, bootstrap, and simultaneous inference
- 📈 Nonparametric: KDE, kernel regression, kernel approximation, B-splines, and GAM
- 🧬 Unsupervised: PCA, KMeans, DBSCAN, GMM, UMAP, t-SNE, NNDescent, and related methods
- 📐 Distributions: backend-aware distribution functions through
get_distribution() - 🧪 Multiple testing:
adjust_pvalues,combine_pvalues, andpermutation_test - 🔁 Cross-validation:
PenalizedGLM_CV,RidgeCV,LassoCV,ElasticNetCV,LogisticRegressionCV, andCoxPHCV
Full method list with solvers, penalties, and link functions →
- English docs: Online documentation · Source
- Chinese docs: 在线文档 · 源码
- Quickstart: Quickstart
- Implemented methods: Method Inventory
- GLM + Penalty: Generalized Linear Model
- Cross-validation: Cross-Validation Guide
- Loss × Penalty × Solver Framework: Framework Guide
- Solver-Penalty Matrix: Solver × Penalty
- Survival analysis: Cox Proportional Hazards
- Panel models: Panel Data Models
- Device & memory: Device and GPU Memory
- PyTorch backend: PyTorch Backend
- Distribution API: Distribution API
- Multiple testing: Overview and tutorials · Adjustment and combination API
- Contributing: Contributor Guide
- Releasing: PyPI Release Guide
- Changelog: Changelog
# CPU only
pip install statgpu
# CuPy backend — choose the CUDA major version that matches your environment
pip install "statgpu[gpu11]"
pip install "statgpu[gpu12]"
# PyTorch backend
pip install "statgpu[torch]"
# Formula/dataframe interfaces
pip install "statgpu[formula]"
# Optional statsmodels dependency for external Cox validation
pip install "statgpu[survival]"
# Development environment
pip install -e ".[dev,validation,formula]"Choose CuPy and PyTorch builds compatible with the installed CUDA driver and runtime.
The default example runs after the base pip install statgpu installation. Use an
explicit GPU device only after installing the corresponding CuPy or PyTorch extra.
import numpy as np
from statgpu import adjust_pvalues, combine_pvalues
from statgpu.inference import norm
from statgpu.linear_model import LinearRegression, PenalizedGLM_CV
# Native distribution sampling uses NumPy's global seed.
np.random.seed(42)
X = norm.rvs(size=(300, 8), backend="numpy")
y = X @ norm.rvs(size=8, backend="numpy") + norm.rvs(size=300, backend="numpy") * 0.5
model = LinearRegression(device="cpu")
model.fit(X, y)
print(f"R²: {model.score(X, y):.4f}")
# Native poisson.rvs takes a scalar mean. NumPy supports one mean per row.
rng = np.random.default_rng(42)
y_pois = rng.poisson(np.exp(X[:, :5] @ np.ones(5) * 0.1))
cv_model = PenalizedGLM_CV(
loss="poisson",
penalty="elasticnet",
l1_ratio=0.5,
alpha_grid=np.logspace(-2, 0, 8),
cv=3,
device="cpu",
compute_inference=False,
)
cv_model.fit(X[:, :5], y_pois)
print(f"Best alpha: {cv_model.alpha_:.4f}")
reject, pvals_adj = adjust_pvalues(
np.array([0.003, 0.02, 0.5]), method="bh",
)
stat, p_global = combine_pvalues(
np.array([0.01, 0.07, 0.03, 0.40]), method="fisher",
)import statgpu as sg
# Global setting
sg.set_device("cuda")
sg.set_device("cpu")
sg.set_device("auto")
# Per-model setting; requires the matching GPU extra and runtime
from statgpu.linear_model import LinearRegression
model = LinearRegression(device="cuda", n_jobs=4)Historical reports are available for GLM solvers (2026-06-23) and unsupervised methods (2026-06-27). Both reports identify Tesla P100 hardware. They are dated snapshots, not measurements of the current source or guarantees for another GPU or workload. See the historical attribution record for the limitations of older comparison tables.
Check correctness and align the statistical objective before comparing speed. A useful benchmark records its source commit, hardware and package versions, workload, timing/synchronization and transfer boundaries. Coefficient correlation alone does not prove coefficient accuracy, calibrated inference, or backend parity.
Contributions are welcome, including bug fixes, documentation, tests, statistical validation, GPU performance work, and new methods.
- Read the Contributor Guide before making a substantial change.
- Open an issue first for new estimators, public API changes, inference methods, solvers, penalties, or large refactors.
- Install development and validation dependencies with
python -m pip install -e ".[dev,validation,formula]". - Add focused tests and run the relevant CPU and physical-GPU checks.
- Update English and Chinese documentation and changelogs for user-visible behavior changes.
Maintainers preparing a package release should follow the PyPI Release Guide.
- Python >= 3.9
- NumPy >= 1.20
- CuPy optional, using the wheel matching the CUDA major version
- PyTorch optional, using a CUDA-compatible build for GPU execution
- CUDA runtime compatible with the selected CuPy or PyTorch build
Apache License 2.0 — see LICENSE.