Skip to main content

GPU-accelerated statistical methods with sklearn-compatible API

Project description

statgpu

PyPI version Python versions License GitHub stars Downloads

GPU-accelerated statistical methods with sklearn-compatible API.

Documentation

Features

  • 🚀 3 Backends: NumPy (CPU), CuPy (CUDA), PyTorch (CUDA) — automatic device selection
  • 🔧 sklearn-compatible: fit/predict/score API, sklearn.base.clone() supported
  • 📊 GLM + Robust + Quantile + Cox: 10+ loss types (quantile, huber, bisquare, fair, cox_ph + 7 GLM families)
  • 🔥 10 Penalties: l1, l2, elasticnet, scad, mcp, adaptive_l1, group_lasso, group_mcp, group_scad
  • 8 Solvers: exact, newton, lbfgs, irls, fista, fista_bb, proximal_irls_cd, proximal_newton — solver="auto"
  • 🧮 Inference: HC0-HC3/HAC robust SE, debiased Lasso, bootstrap, simultaneous CI
  • 📈 Nonparametric: KDE, kernel regression, B-splines, GAM
  • 🧬 Unsupervised: PCA, KMeans, DBSCAN, GMM, UMAP, t-SNE, NNDescent (12+ classes)
  • 📐 Distributions: 15 distributions across 3 backends via get_distribution()API docs
  • 🧪 Multiple Testing: adjust_pvalues + combine_pvalues + permutation_test
  • 🔥 Cross-Validation: PenalizedGLM_CV (all losses × 10 penalties), RidgeCV, LassoCV, ElasticNetCV

Implemented Methods

Full method list with solvers, penalties, link functions →

Category Classes Highlights
Regression & GLM 12 classes LinearRegression, Ridge, Lasso, ElasticNet, Logistic, Poisson, Gamma, InvGauss, NB, Tweedie, Ordered models
Penalized GLM 11 classes PenalizedGLM + 7 family wrappers + PenalizedQuantileRegression, PenalizedRobustRegression, PenalizedCoxPHModel × 10 penalties × 8 solvers
Cross-Validation 6 classes RidgeCV, LassoCV, ElasticNetCV, LogisticCV, PenalizedGLM_CV, CoxPHCV
ANOVA 2 functions f_oneway, f_twoway — GPU-accelerated
Covariance 3 classes EmpiricalCovariance, LedoitWolf, OAS
Panel Data 2 classes PanelOLS, RandomEffects
Nonparametric 5 classes KernelRidge, KernelRidgeCV, pairwise_kernels, bspline_basis, natural_cubic_spline_basis
Semiparametric 1 class GAM (penalized B-splines + GCV)
Unsupervised 12 classes PCA, SVD, NMF, UMAP, t-SNE, KMeans, DBSCAN, GMM, AgglomerativeClustering
Survival 1 class CoxPH (Breslow/Efron ties, robust SE)
Feature Selection 2 functions fixed-X / model-X knockoff filters
Multiple Testing 3 functions adjust_pvalues, combine_pvalues, permutation_test

Installation

# CPU only
pip install statgpu

# With GPU support (choose by CUDA major version)
# CUDA 11.x runtime:
pip install statgpu[gpu11]

# CUDA 12.x runtime:
pip install statgpu[gpu12]

# With PyTorch backend (CUDA 11.x)
pip install statgpu[torch]

# Development
pip install statgpu[dev]

# Formula interface
pip install statgpu[formula]

Quick Start

import numpy as np
from statgpu.inference import norm, poisson
from statgpu.linear_model import LinearRegression, PenalizedGLM_CV
from statgpu import adjust_pvalues, combine_pvalues

# Generate data using statgpu distributions (scipy-compatible API)
X = norm.rvs(size=(10000, 100))
y = X @ norm.rvs(size=100) + norm.rvs(size=10000) * 0.5

# Linear regression with GPU
model = LinearRegression(device='cuda')
model.fit(X, y)
print(f"R²: {model.score(X, y):.4f}")

# Penalized GLM with cross-validation
y_pois = poisson.rvs(mu=np.exp(X[:, :5] @ np.ones(5) * 0.1), size=X.shape[0])
cv_model = PenalizedGLM_CV(
    loss="poisson", penalty="elasticnet", l1_ratio=0.5,
    cv=5, device="cpu",
)
cv_model.fit(X[:, :5], y_pois)
print(f"Best alpha: {cv_model.alpha_:.4f}")

# Multiple-testing correction
reject, pvals_adj = adjust_pvalues(np.array([0.003, 0.02, 0.5]), method='bh')

# Global p-value combination
stat, p_global = combine_pvalues(np.array([0.01, 0.07, 0.03, 0.40]), method='fisher')

Device Control

import statgpu as sg

# Global setting
sg.set_device('cuda')  # Force GPU
sg.set_device('cpu')   # Force CPU
sg.set_device('auto')  # Auto-detect (default)

# Per-model setting
from statgpu.linear_model import LinearRegression
model = LinearRegression(device='cuda', n_jobs=4)

Benchmark Results (RTX 4090)

Full reports: results/unsupervised_bench_2026-06-27.md, results/glm_solver_benchmark_2026-06-23.md

Test environment: RTX 4090 (24GB), CuPy 14.1.0, PyTorch 2.8.0+cu128, scikit-learn 1.8.0, statsmodels 0.14.6, lifelines 0.30.3
Benchmark environment only; not installation requirements.

Real-Data Performance

Module Dataset n p Best Speedup Precision
Poisson GLM freMTPL2 678K 42 196.9x vs sklearn coef_corr=1.000000
Gamma GLM synthetic 678K 42 97.9x vs sklearn coef_corr=0.9995
CoxPH synthetic 1.9K 500 1.2x vs CPU coef_corr=1.000
adjust_pvalues (BH) synthetic 1M 0.55x 100% agreement
PenalizedPoisson(L1) freMTPL2 678K 42 OK
PenalizedCoxPH(L2) synthetic 1.9K 500 C-index match

Precision Summary

Module Metric Result
Poisson GLM coef correlation vs sklearn 1.000000 (full freMTPL2)
Gamma GLM coef correlation vs sklearn 0.9995
CoxPH coef correlation vs lifelines 1.000
adjust_pvalues (BH) reject agreement vs statsmodels 100% (100K to 5M p-values)
Penalized (L1/L2) self-consistency C-index match across penalties

Requirements

  • Python >= 3.8
  • NumPy >= 1.20
  • CuPy (optional, for GPU; choose wheel matching CUDA major version)
    • CUDA 11.x: cupy-cuda11x
    • CUDA 12.x: cupy-cuda12x
  • CUDA runtime compatible with selected CuPy wheel

License

Apache License 2.0 — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statgpu-0.2.0.tar.gz (585.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statgpu-0.2.0-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file statgpu-0.2.0.tar.gz.

File metadata

  • Download URL: statgpu-0.2.0.tar.gz
  • Upload date:
  • Size: 585.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for statgpu-0.2.0.tar.gz
Algorithm Hash digest
SHA256 74ae2314950b5eb957e4cc4030cab4e14b0f0b7cd48db9f627930cfb2676dad8
MD5 eb51477a0445d73d457d5fe9ab20431a
BLAKE2b-256 432e192911cf8fae1d88f0964008a2bb67a8bf145abc87b07a61f9d0cd48f9d8

See more details on using hashes here.

File details

Details for the file statgpu-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: statgpu-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for statgpu-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2f27f70afbcae7829c7abdcc8dcbb88762f72ff3c665f20bdce86c0d664e5a05
MD5 b7a114a60a3510adf2982a5b636f9c69
BLAKE2b-256 626d23d9bdc1c816a806c2ba32d6c56ae40bcd37da4ba21ecaaed5fb6d21967d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page