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
  • 📊 7 GLM Families: squared_error, logistic, poisson, gamma, inverse_gaussian, negative_binomial, tweedie
  • 🔥 10 Penalties: l1, l2, elasticnet, scad, mcp, adaptive_l1, group_lasso, group_mcp, group_scad
  • 6 Solvers: exact, newton, lbfgs, irls, fista, fista_bb — solver="auto" selects optimal
  • 🧮 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 (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 7 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 8 classes PenalizedGLM + 7 family wrappers (Linear, Logistic, Poisson, Gamma, InvGauss, NB, Tweedie) × 10 penalties × 6 solvers
Cross-Validation 6 classes RidgeCV, LassoCV, ElasticNetCV, LogisticCV, PenalizedGLM_CV, CoxPHCV
ANOVA 1 function f_oneway — 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 report: dev/tests/_bench_realdata_report.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

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.1.1.tar.gz (519.5 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.1.1-py3-none-any.whl (637.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for statgpu-0.1.1.tar.gz
Algorithm Hash digest
SHA256 120c43912d848a15b7f7407e30b11467de7f5dec073e2270f4a6fe99e7277840
MD5 f3c6268c5db02a92039ee8f414b775b4
BLAKE2b-256 4227f03f7dda4381e4fec6490ba876b2bb1aeb4dc86455233b60b1278121704b

See more details on using hashes here.

File details

Details for the file statgpu-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: statgpu-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 637.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for statgpu-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aba34c2f4ab72a09b4be210cd40cfb2dcd34e8069d0543f4aa15ae5f0f34d986
MD5 fde8d188129a729361c179791b23e243
BLAKE2b-256 b001e6c2ddd734d7548cb6115fdc44335201266801b93fd84f30f591436e60d3

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