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.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)
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
Hashes for python_glmnet-2.2.2.post2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5af21883cbe9c82eba44c5ee3e7639d391ef387e8681f45a7e54237705fa12b |
|
MD5 | 90d5f861a2c9081639046e0317865c5b |
|
BLAKE2b-256 | f46778ffb8ea171d4cb1274b997cb701245d180d896c75c35a45843c54470f5a |
Hashes for python_glmnet-2.2.2.post2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162362889d15fe12e7e94d125938541789531fdcc3a89c3b731a36561b489d57 |
|
MD5 | 0ca4126b0e334bf647b65b33616eb6e1 |
|
BLAKE2b-256 | d5dee6ed491f67138dcc2d2cf3c9063e8a1c338eddd354e599faa79bf816409f |
Hashes for python_glmnet-2.2.2.post2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 680fdee07c588d607d764f1f4060c5080769f3026c6c407832779b912a319587 |
|
MD5 | 3bbf304425b68100790fdad00d706c0f |
|
BLAKE2b-256 | c803f569e7ad29d367bd5db29e3bb94ed27d93932b7e675b0fdd917f4b5ae20b |
Hashes for python_glmnet-2.2.2.post2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b6d2e63de769c0b61c9b4dbe84d827aad3e5e404daf85f02178203892827910 |
|
MD5 | 67a6f1eab01cc2e6816f8c72d0c9bc0d |
|
BLAKE2b-256 | 6864e6d2e52f9d312c7b548ef8ea8545d9083fab28476a60d98054081f215f07 |
Hashes for python_glmnet-2.2.2.post2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cf93077079e189a701452c0f307f9dbeb977f03520e09f14ee4e313007c0683 |
|
MD5 | 10704ba763ffce1f09227df32edc1efa |
|
BLAKE2b-256 | b1aa21c09ff47a38b6afa222be237d45d995ee07dc4eaa81a7f7b13978f5569d |
Hashes for python_glmnet-2.2.2.post2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8bedbeeac5978d3f678b374ac79951276f86a34d2fc89dbccd17f2e79f05ec0 |
|
MD5 | a7a54e1e949d6d55f107cb09093c0c71 |
|
BLAKE2b-256 | cd3d5e559b049f96b393de36e758c4fc175a54855950f8e51cf5c7db94d6374c |
Hashes for python_glmnet-2.2.2.post2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03214994cf980e3e372191f81572a9535f01a591aa9cb3d6c0a9af57ece01fa7 |
|
MD5 | 09b5c498789e85e3c660a2c1426d16ae |
|
BLAKE2b-256 | 5604601e47e9d33e02e5f54eff972901bed2b41f5e8334bfddecf92e0e9275c4 |
Hashes for python_glmnet-2.2.2.post2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fecb8e1ed1a9473f4dc927f14372d30602cf6b4f023ee79a46e29d73712e464 |
|
MD5 | e3fab3936d56e6dca9147612bc0fea5b |
|
BLAKE2b-256 | cc569f1bd0a9b17f758cc3733e75e6b1210fe6feb368de4517b02a24c217e6b1 |
Hashes for python_glmnet-2.2.2.post2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20d753fc892bab63b8f5ef8393b8a1563eb5011a96f8fecfddc03b9752de18df |
|
MD5 | 94b69c890d45d85bd35eae7b67dc3f47 |
|
BLAKE2b-256 | 443015191805983f828b000869d8c4d1258a4c450c02f1823535f6c3c91dbeab |
Hashes for python_glmnet-2.2.2.post2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1925becce05e047908fb902950607ecb5393b7b628db0fadf7d287fbc353f2f |
|
MD5 | f12e7823d60287dd2f8bf6cfc581ad69 |
|
BLAKE2b-256 | e04c89c6d3f8c89e31eed834469e9d9043f2acc398d9dd27b6489775d4944c0b |
Hashes for python_glmnet-2.2.2.post2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7b8864a591962910425ca3e6772ce7487696197a77e81bc3d2e713867f7a49 |
|
MD5 | f7ccb64d4aede8011d17463fd9b88958 |
|
BLAKE2b-256 | b60b66e33307ea7b3934791aa4269eb46b68a738518a73cdd493c2f38bb0738f |
Hashes for python_glmnet-2.2.2.post2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab0b1ce9b22632299f96f73776b221bb634684712bbdca8f3ccd53337e022015 |
|
MD5 | 7e752ec1d91ad50f481a554335aff1f8 |
|
BLAKE2b-256 | 9383c3839aceee53412af47999c00cdf52a1e8f181500916752afa3d13aa6c64 |
Hashes for python_glmnet-2.2.2.post2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 201191248b1e3dae1c50f10bd95bf817edc0ffd6d3d2f04837df1803fefbe326 |
|
MD5 | 2450ab41fca4e7cd22e13a4e0d6a0f38 |
|
BLAKE2b-256 | 4aec1c6caabf744a39be0baed60cacbcb2f7dc269304703c733a97ab0b26a244 |