glmstar
A Python implementation of the glmnet algorithm for fitting generalized linear models via penalized maximum likelihood. This package provides fast and efficient regularization paths for linear, logistic, multinomial, Poisson, and Cox regression models.
Features
- Multiple GLM Families: Support for Gaussian (linear), Binomial (logistic), Multinomial, Poisson, and Cox regression
- Elastic Net Regularization: Combines L1 (Lasso) and L2 (Ridge) penalties with mixing parameter α
- Fast Path Algorithms: Efficient computation of regularization paths using coordinate descent
- Cross-Validation: Built-in cross-validation for optimal λ selection
- Prediction Methods: Interpolation and prediction at arbitrary λ values
- sklearn Compatibility: Follows scikit-learn API conventions
- C++ Backend: High-performance C++ implementation with pybind11 bindings
Installation
Get the source
The C++ code depends on two git submodules, Eigen and glmnetpp, so clone recursively:
git clone --recursive https://github.com/jonathan-taylor/pyglmnet.git
cd pyglmnet
# Or, if already cloned without submodules
git submodule update --init --recursive
A C++17 compiler is required to build the extension modules.
Development install with uv (recommended)
uv sync # editable install plus build and test tools (the `dev` group)
uv run pytest tests --test-size=small
The project uses meson-python, whose editable installs recompile the C++ extensions on
import. For that reason pyproject.toml disables build isolation for glmstar under
uv, so the build tools (meson, ninja, pybind11, ...) must live in the project
environment -- uv sync takes care of this. To target an already-activated venv other
than .venv, use uv sync --active.
If you prefer uv pip, install the build tools first:
uv pip install meson-python meson ninja pybind11 setuptools_scm
uv pip install -e . # or `uv pip install .` for a regular install
Running uv pip install . without them fails with No module named 'mesonpy'.
Install with pip
pip install .
For an editable install with pip, again install the build tools into the environment and disable build isolation:
pip install meson-python meson ninja pybind11 setuptools_scm
pip install --no-build-isolation -e .
Troubleshooting
If the build fails with 'pybind11/pybind11.h' file not found, a stale meson build
directory (e.g. build/cp310) is pointing at a temporary build environment that no
longer exists. Delete it and reinstall:
rm -rf build/cp*
uv sync
Quick Start
import numpy as np
from glmnet import GaussNet, LogNet
from sklearn.datasets import make_regression, make_classification
# Linear Regression
X, y = make_regression(n_samples=100, n_features=20, n_informative=5, random_state=42)
fit_gaussian = GaussNet().fit(X, y)
# Plot coefficient paths
ax = fit_gaussian.coef_path_.plot()
ax.set_title('Linear Regression Coefficient Paths')
# Logistic Regression
X, y = make_classification(n_samples=100, n_features=20, n_informative=5, random_state=42)
fit_logistic = LogNet().fit(X, y)
# Cross-validation
cvfit = LogNet().fit(X, y)
_, cvpath = cvfit.cross_validation_path(X, y, cv=5)
ax = cvpath.plot(score='Binomial Deviance')
Available Models
- GaussNet: Linear regression (Gaussian family)
- LogNet: Logistic regression (Binomial family)
- MultiClassNet: Multinomial regression
- FishNet: Poisson regression
- MultiGaussNet: Multi-response linear regression
- CoxNet: Cox proportional hazards model
Key Features
Elastic Net Regularization
# Lasso (α=1, default)
fit_lasso = GaussNet(alpha=1.0).fit(X, y)
# Ridge (α=0)
fit_ridge = GaussNet(alpha=0.0).fit(X, y)
# Elastic Net (α=0.5)
fit_elastic = GaussNet(alpha=0.5).fit(X, y)
Cross-Validation
# Perform cross-validation
cvfit = GaussNet().fit(X, y)
_, cvpath = cvfit.cross_validation_path(X, y, cv=5)
# Get optimal lambda
lambda_min = cvpath.index_best['Mean Squared Error']
coef_min, intercept_min = cvfit.interpolate_coefs(lambda_min)
Prediction and Interpolation
# Predict at specific lambda values
predictions = fit_gaussian.predict(X_new, interpolation_grid=[0.1, 0.05])
# Interpolate coefficients
coef, intercept = fit_gaussian.interpolate_coefs(0.5)
Weights and Offsets
import pandas as pd
# Create DataFrame with response, weights, and offsets
Df = pd.DataFrame({
'response': y,
'weight': sample_weights,
'offset': offsets
})
# Fit with weights and offsets
fit = GaussNet(response_id="response",
weight_id="weight",
offset_id="offset").fit(X, Df)
Dependencies
- Core: numpy, scipy, pandas, scikit-learn, joblib, statsmodels, coxdev, tqdm, mpmath
- Build: meson-python, meson, ninja, pybind11, setuptools_scm
- Optional: matplotlib (plotting), pytest (tests)
Development
Building from Source
See Installation; uv sync builds the C++ extensions in place and
rebuilds them automatically on import after source changes.
Running Tests
# Run all tests (or prefix with `uv run`)
pytest tests/
# Quicker subset
pytest tests --test-size=small
# Run specific test suites
pytest tests/paths/
pytest tests/compare_R/
Citation
If you use this package in your research, please cite:
Friedman, J., Hastie, T., & Tibshirani, R. (2010).
Regularization paths for generalized linear models via coordinate descent.
Journal of Statistical Software, 33(1), 1-22.
License
This project is licensed under the BSD-3-Clause License - see the LICENSE.txt file for details.
Authors
- Trevor Hastie (hastie@stanford.edu)
- Balasubramanian Narasimhan (naras@stanford.edu)
- Jonathan Taylor (jonathan.taylor@stanford.edu)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Acknowledgments
This package is based on the original R glmnet package by Jerome Friedman, Trevor Hastie, Rob Tibshirani, and others. The C++ implementation uses the Eigen library for linear algebra operations.
Metadata
Release files for glmstar 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| glmstar-0.1.3.tar.gz | 11.2 MB | Details |
Built distributions (wheels)
Total release size: 137.3 MB
Release files / glmstar-0.1.3.tar.gz
| Download URL | glmstar-0.1.3.tar.gz |
|---|---|
| Size | 11.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43d68c105314a72103801ba17c6d70cf4104b2aa0610610eb81a47cd3169a83f
|
|
BLAKE2b-256 checksum How to use checksums |
2004101c7a2c1c4d660cef62c5e67f8f092090dd648f6566303e6440fbbee950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314t-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp314-cp314t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
5dd8a5f791585186ce7bf8ad4cd5ac42d92e64cd59d318e7eaeab1a4d7cb2579
|
|
BLAKE2b-256 checksum How to use checksums |
a4cb2cb5ed34cc12a9004e82c44efc2348ebf661580aff635bfb0e185197c3ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
8151cfcbd388e83f2e6f1b5cbb7aac15696515fb6df2b261d7b6fc814bd4734a
|
|
BLAKE2b-256 checksum How to use checksums |
dbd8254b741f4adba1fa2adf67dafce88a4340124a2b7343ea1e33356928338c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
575d4661f7a78e8bb88314105d0db6f8dc9461669d3c36093ea3040127484377
|
|
BLAKE2b-256 checksum How to use checksums |
4c3784d15d1f15641e1b8a6fa7f08e4bf9137e4230511a270eb8722fd77f94d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9f1b6b1313eca5b39de43c23edcb8c561bda8da1082f378faa9b5ca49cdbffc6
|
|
BLAKE2b-256 checksum How to use checksums |
f3afca843cfe80d6e91b775c1b9169ac4314f49a838ccbd5eb43370a40c9e6f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
76325c8b827c4c63445936661336346f9460793f038de9971bcfd3a17300ecb9
|
|
BLAKE2b-256 checksum How to use checksums |
9a5544cbf8a58c5d9ded6d92cd10dc420ecd57a3cc44c9e492084f4d26c93382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0aacd6c7eb702f070da2dc58265146a529184b0f04a14f2d14f6582da3582ae6
|
|
BLAKE2b-256 checksum How to use checksums |
849e16e6c33241ce9e1b7f8462650c215b5f840aa9386d6647ff226ad1daaf57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
48aa9e829ac28a1bb94df3053b05a5c72b4ace8e41ec3e9ebf290fa4cf80c868
|
|
BLAKE2b-256 checksum How to use checksums |
850d4781c57e3b6eba88b53cd6829d508fe7474b3e9d3b2bcaccad193892d207
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
907877e4175bccef0c5d9d52538ace472f7ad6589051052873e8a08bcc567dc1
|
|
BLAKE2b-256 checksum How to use checksums |
d21db60b908916001ebc6691b88706fb3017da255baa373e3968620d2e5d5ce9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b012eb456c8d73bacb426fd45e7004ce616d8a0fcc966a99c15995d1a943c87d
|
|
BLAKE2b-256 checksum How to use checksums |
5b9214c7f532a9c7d62217e6f9a3593c8d8e806197a563f587aa754d1aa7f296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
3cbd248491798445cdbe26dca737e0fca02e4b839e80e7d107c206d54af6afcf
|
|
BLAKE2b-256 checksum How to use checksums |
50e6a09510ba4be256d86b380730ec734f665fa85e2251f1c60e7606a5c3b6a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
93e2d77c3be5db6e96ce8bb9d9807e0706abe11aaeb25c857240c42e7895202e
|
|
BLAKE2b-256 checksum How to use checksums |
bb1e2c113883a937866eb2064f606d58f155a93b5c1cc0a839431c51f8da80f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ca1e9a7af8e9ebd530df0539cd3028d567a2b2bfc7c447a1ad1dce49e13f55d2
|
|
BLAKE2b-256 checksum How to use checksums |
bc822ccafb427e684081eabfaff83c511ef42d54cc69423715402450f538421a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
d85fa092adb24c36faa75eafd8af70341ec206cf7131cba085e3a23a2511c098
|
|
BLAKE2b-256 checksum How to use checksums |
e734cb7923d9ed94dd835b0d01ebc17414163ae01a9f8269239b6e4a801a9b10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1be941d7ac3fde00b3ba7f727b70c4bf364b2c839c62fd69d00bd4e278e940d7
|
|
BLAKE2b-256 checksum How to use checksums |
18b50fab5f995b97b3ad4c054c5947f5268989aa47da31f207ac465e8c8ebace
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
516252eb020769b49a48c780a62c8eba350afb6d12422115e73dba4e864f50fb
|
|
BLAKE2b-256 checksum How to use checksums |
943e7bd18d49ead0469264a471f5dc79233aebc5e8c7459e2eab36746cfac7bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
c2288d4800533176b22808b7be79e015a5f981c13a4e5f754b6299e2d50a099c
|
|
BLAKE2b-256 checksum How to use checksums |
1c59cdb1ca15cce6342fd88aaff5f5471372a553bdf90fc62b41d929b8e92bdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a92b73730a95ca28313dfcd3d88fcf2a52a72540a6008f4d4dc8f56790a9a38f
|
|
BLAKE2b-256 checksum How to use checksums |
77d800bc2f838e31b04fc7eb097d935521526466075bbdef027cba365b14512b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1bfc050dd3e9019309c255522328a0dccfc8079264bb63ef13769175c7819b4e
|
|
BLAKE2b-256 checksum How to use checksums |
fbe915d9cf6cbc4020c4246d131b977e235a2fc42c0e8d5128cb3c5d1281f22a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp39-cp39-musllinux_1_2_x86_64.whl
| Download URL | glmstar-0.1.3-cp39-cp39-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
68d35774b99b0dfcec0789ada3d2b666bc48521da4ec06ddc3571a5e9fa90186
|
|
BLAKE2b-256 checksum How to use checksums |
bd5a212eb2a6d014fa0341c4b57d4ea0c32ba8d07e570f5de2999e58eb483c03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | glmstar-0.1.3-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.9 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
fa38a2730e6b3fd118f4676f116d3d046e9646932d24135e81cb5c6a463fd98d
|
|
BLAKE2b-256 checksum How to use checksums |
5b2d8b869ce3579b6fcf0747a782d5acf1d288510cff4197e3bdcabf1168f105
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / glmstar-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | glmstar-0.1.3-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c40ce9d071509df2833296b1672379a5f6e742e82cfa12aabfd1b645d289bca4
|
|
BLAKE2b-256 checksum How to use checksums |
724fddfd85f4d290dfe4d73eee6ed0ee631669a683129f8e7242183183e823fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|