Python wrapper for glmnet
Project description
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.6, 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 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file python_glmnet-2.2.2.post1.tar.gz
.
File metadata
- Download URL: python_glmnet-2.2.2.post1.tar.gz
- Upload date:
- Size: 89.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54e68a9499f70b9df4f0ed4b11c2e2bba9095b290d2faf4a2f6cc2cc50d2bcc1 |
|
MD5 | d08010f0e4831cc04c5d7c9151b20bbc |
|
BLAKE2b-256 | 580e1ca3d04182fbcfd24f380e35820793899a92ba000043eab2ffa80dde944e |
File details
Details for the file python_glmnet-2.2.2.post1-cp311-cp311-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f51193b3f02f25fb0411bad1c37c4fcd62ddcbe62bbcbdca0a2b8f39c61bc0 |
|
MD5 | 5ab551091ce571964a437169597735bf |
|
BLAKE2b-256 | 827345b86b4b6e844016a28db78f5fa92330f13c98087b25bc760e3ec60eaa88 |
File details
Details for the file python_glmnet-2.2.2.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 666061b8b1b5d1d9359346bcf3ad73a0274217cfd795c9bbaf23b77340492ba3 |
|
MD5 | b23a11c69fb75885dee8222cd3f7c3b9 |
|
BLAKE2b-256 | fa43e3eb73ac1813f15fe7096960e4daf080ec6e57ce79ca72bce11ed65b9393 |
File details
Details for the file python_glmnet-2.2.2.post1-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf623a606bf932928d4f18716dc545551158e6202f4e2db080063891448aed5 |
|
MD5 | f552876486679592226e48f02e41904a |
|
BLAKE2b-256 | 4ad4a3223a7b328d4a98c859ebc8ed625a5bc75db4fa0b3d02d68f867f0bed52 |
File details
Details for the file python_glmnet-2.2.2.post1-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c382f4dac22e051edff6911e0f0164acbb1037eb3bebc54e96dbaaaa3d6febd |
|
MD5 | 9cf9cf1e8562718136c7eb76945b786e |
|
BLAKE2b-256 | 75431cfcdeb307d932512dc1bb5934e12ac23a6942dfd240583d470afd3c95f2 |
File details
Details for the file python_glmnet-2.2.2.post1-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 253d1dc6a66494433292613fc4a430c96eb6fe586f232a7f69b3059b4e06ff29 |
|
MD5 | bea282465c2306548f164e40521bb200 |
|
BLAKE2b-256 | 9b6ec0c6bec20f61fad71f4c35cdaa30ae7df244d05e2ea2988e73b15bc06d9f |
File details
Details for the file python_glmnet-2.2.2.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b074e918676e01aa5530763bdd49143070d68e22d46f4cfd86adbef511abe949 |
|
MD5 | ca7a875b4f65bb67de3809c300c0423a |
|
BLAKE2b-256 | 90f5d68e05da27049a6457dafdd05e7f099d5822d064de6afb327d7b0fe79fdf |
File details
Details for the file python_glmnet-2.2.2.post1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf680b8497983c192b73ab91dd75fff499621433ba540c10dfdf98ac07641fa6 |
|
MD5 | a257b423fb56b345d58dce82fc009bf5 |
|
BLAKE2b-256 | 0d1ba194241d01517e1976e50fa642d2aa39102cff04d2b217e22d4b5921fde6 |
File details
Details for the file python_glmnet-2.2.2.post1-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a20b7844810a598edb997f327c9681b3e6039f10090184139fb4d676ccc0aa43 |
|
MD5 | 7ff4bdb92d3dd68363a3444812de7933 |
|
BLAKE2b-256 | a45e1fca8accb50794902d27caa9d4396cb4cee6c766c7fef0bb4685291ffcd9 |
File details
Details for the file python_glmnet-2.2.2.post1-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a537b0bb90d578bc139b2729684b0b626d4001204002d418b9bfbf159e1cd7 |
|
MD5 | dbb65af7e418dead392002000ab828a2 |
|
BLAKE2b-256 | 3187dc89e53e79b6cdd06eb4cd8fc288072b0f0cc2e6c97a3a417b7df1da2d70 |
File details
Details for the file python_glmnet-2.2.2.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207c9d7909e6439682c960a34e8f8cbc5f7097122debb2485c44df1a325131c3 |
|
MD5 | 80df74f56c7fe795f0c92a8eae008648 |
|
BLAKE2b-256 | 03c7f935e8ffb3a2d7883ef11af98f927b7c7b925d4305bf73cdfd575905a36a |
File details
Details for the file python_glmnet-2.2.2.post1-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d0b6e3c71054272f2c33aac7b20476f95bd2fd76eb7ab4871f35ebfae2378d |
|
MD5 | cbcbf6f91e6ba64fd599cfc76e41acc4 |
|
BLAKE2b-256 | b96edb698e633ea570e1d89e3bc7a6667d5539df4efc82d180f224a0855fc9c2 |
File details
Details for the file python_glmnet-2.2.2.post1-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: python_glmnet-2.2.2.post1-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aaa8c9ebf4846762b63c6ee2df3b700f5ff25ffdfa7f55152c74e5a5d43abdb |
|
MD5 | 27d00475a3ebfcc3fe518588d9aceb74 |
|
BLAKE2b-256 | a8d8e62d1ea2013163648737d1d6b1e22c50ff57463e30112772d764ec7e186b |