Fork of python-glmnet with support for more recent Python versions.
This is a Python wrapper for the fortran library used in the R package glmnet. While the library includes linear, logistic, Cox, Poisson, and multiple-response Gaussian, only linear and logistic are implemented in this package.
The API follows the conventions of Scikit-Learn, so it is expected to work with tools from that ecosystem.
Installation
requirements
python-glmnet requires Python version >= 3.9, scikit-learn, numpy, and scipy. Installation from source or via pip requires a Fortran compiler.
conda
conda install -c conda-forge glmnet
pip
pip install python-glmnet
source
glmnet depends on numpy, scikit-learn and scipy. A working Fortran compiler is also required to build the package. For Mac users, brew install gcc will take care of this requirement.
git clone git@github.com:replicahq/python-glmnet.git
cd python-glmnet
python setup.py install
Usage
General
By default, LogitNet and ElasticNet fit a series of models using the lasso penalty (α = 1) and up to 100 values for λ (determined by the algorithm). In addition, after computing the path of λ values, performance metrics for each value of λ are computed using 3-fold cross validation. The value of λ corresponding to the best performing model is saved as the lambda_max_ attribute and the largest value of λ such that the model performance is within cut_point * standard_error of the best scoring model is saved as the lambda_best_ attribute.
The predict and predict_proba methods accept an optional parameter lamb which is used to select which model(s) will be used to make predictions. If lamb is omitted, lambda_best_ is used.
Both models will accept dense or sparse arrays.
Regularized Logistic Regression
from glmnet import LogitNet
m = LogitNet()
m = m.fit(x, y)
Prediction is similar to Scikit-Learn:
# predict labels
p = m.predict(x)
# or probability estimates
p = m.predict_proba(x)
Regularized Linear Regression
from glmnet import ElasticNet
m = ElasticNet()
m = m.fit(x, y)
Predict:
p = m.predict(x)
Metadata
Release files for python-glmnet 2.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_glmnet-2.6.1.tar.gz | 125.9 kB | Details |
Built distributions (wheels)
Total release size: 21.1 MB
Release files / python_glmnet-2.6.1.tar.gz
| Download URL | python_glmnet-2.6.1.tar.gz |
|---|---|
| Size | 125.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6addc9e7cfe6c7df1e2e2f261098661b199d52458b558c394b7abd7e98be6e94
|
|
BLAKE2b-256 checksum How to use checksums |
19033a8be0259cc77001327c0aec31d572a4986e5e3239f34e0d5760a73bc47e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
aaaf590fd5c5c1b863cc37c75faf704dd164204b9335e1810eb81875276294a7
|
|
BLAKE2b-256 checksum How to use checksums |
f5df57d2705963949e83c948cdc6d2859beaee780453db20dde520b9a9c535f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e178531829753bed49a7ba3e6f7ddf81f921b43c4326e3597abb0c6ca648c7f9
|
|
BLAKE2b-256 checksum How to use checksums |
68d8324da86f9879e4d1289fbe6ce11edc7a6ebee0227ee23a6f675f1e676ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp313-cp313-macosx_14_0_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp313-cp313-macosx_14_0_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.13 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
09c3e030d5ea6d099c4b63a701ad3223a1472f9354b50607aad21d6ef6406ae1
|
|
BLAKE2b-256 checksum How to use checksums |
944510d83590866052f4998d72a4624cc18a537b41d048a8980e78c8aeebf6cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp313-cp313-macosx_14_0_arm64.whl
| Download URL | python_glmnet-2.6.1-cp313-cp313-macosx_14_0_arm64.whl |
|---|---|
| Size | 935.3 kB |
| Tags | CPython 3.13 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c9b98271f53b9189596ef38ba9528c28472e2400cb813afd08344b99b57042b6
|
|
BLAKE2b-256 checksum How to use checksums |
28edcd0e97b6040f8fe4f156f23a699beb9016bad212c38d5c53af0445be8a31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
5e3925e6a67f8b1f8d1823cd9e2d1d4ad63bab0471b0b1aa5db773151f10833e
|
|
BLAKE2b-256 checksum How to use checksums |
20c09b1491ef91ecf9d604c10401b6dd455d9a9188e8b3f4f11903eefc59190a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
d8c1aaee5f78f9dbdf3a06c6507f9d3ef59434f376d099f8a906afe4f6b17289
|
|
BLAKE2b-256 checksum How to use checksums |
990967e68ca7abd0717f0cd366a97fb0bbce8994aea06b86ca116b54d4e6478d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp312-cp312-macosx_14_0_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp312-cp312-macosx_14_0_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.12 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
a038d6bed83a0ae7cfe1d7e41c03513b3276f546627b85e75f8116126699160f
|
|
BLAKE2b-256 checksum How to use checksums |
80e829c39c94844fdf46241e5bbddda3f557a7cebac093bb292af0ff4fec69ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | python_glmnet-2.6.1-cp312-cp312-macosx_14_0_arm64.whl |
|---|---|
| Size | 935.3 kB |
| Tags | CPython 3.12 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
672a79745f36f9226b7b82082f07457e45a03dfee915310412dbf1f29c3471db
|
|
BLAKE2b-256 checksum How to use checksums |
ad190370b6c2bb5a513ad7a9b204be14214dea459ccc11dc44f6937925bd8fd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9c1d91b628ad4121b68b5d39bb460b46dd829ca419e01f697bfe67dc2fef405a
|
|
BLAKE2b-256 checksum How to use checksums |
0185a0a96e806cd9202898f0cbbad004fbced9a68c8bea14f3713838dff5bb52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0da97e52535b0a09eab9ac0b81810287b2eb9471789386ccf89af8d6b9551c7d
|
|
BLAKE2b-256 checksum How to use checksums |
a0db7b89c12a1739522ff66bf9ed663dfa297999ccc2f6d872795c25588cd18f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp311-cp311-macosx_14_0_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp311-cp311-macosx_14_0_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.11 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
31896723bfe31c8a9363c04542b108b9ace942aeb68dcd40a10992eb71242afc
|
|
BLAKE2b-256 checksum How to use checksums |
25ea6a034a496aa1071d3ff0de4aef7e5e6c21e2b3dbac3345f85e62f6a3770c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | python_glmnet-2.6.1-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 935.2 kB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a67a21b4792ab353669178372049224533647834c0370dd7280b967ca1c53d4e
|
|
BLAKE2b-256 checksum How to use checksums |
7ee21a57ff47d41d484c800d0a8d72c4e16b45f38518e5bbe49533cf23ebf10b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
b66d3540a391ae46a12de0e19c4a18cb5292d86aeb3899ada00eb11fee62a04e
|
|
BLAKE2b-256 checksum How to use checksums |
ab0dc432b43dce69323ecea9ee6545a62e889b781ec844f153ee4594b3b50de9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3e43eb4d38dfe64df836cd6c345791e23d064f1b1a336b84dc86cc4c3bbd153d
|
|
BLAKE2b-256 checksum How to use checksums |
b6e6d7f52671c92c6f569df8cb277ba71b791dc41e2582a098ef789f584293d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp310-cp310-macosx_14_0_x86_64.whl
| Download URL | python_glmnet-2.6.1-cp310-cp310-macosx_14_0_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.10 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
a4934e9ee6f2f4f08fa9c10bea6b47176cc8906d9a6cf8db9f6270436209b419
|
|
BLAKE2b-256 checksum How to use checksums |
94a4029bc5caf624e0de562eb13af70815e75e8cc2db17c270b6bcc337178e7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / python_glmnet-2.6.1-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | python_glmnet-2.6.1-cp310-cp310-macosx_14_0_arm64.whl |
|---|---|
| Size | 935.2 kB |
| Tags | CPython 3.10 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a5a78f93340a987fb1e8ce75e47bb842582a98712639de2ad842e5242dca3f20
|
|
BLAKE2b-256 checksum How to use checksums |
7368fbc06ec68133aaaec52ea836476deb056140c0605e1ce7d6ceef48c819ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|