Skip to main content

Python wrapper for glmnet

Project description

Build status Latest version on PyPI Supported python versions for python-glmnet

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_glmnet-2.6.1.tar.gz (125.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_glmnet-2.6.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

python_glmnet-2.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

python_glmnet-2.6.1-cp313-cp313-macosx_14_0_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ x86-64

python_glmnet-2.6.1-cp313-cp313-macosx_14_0_arm64.whl (935.3 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

python_glmnet-2.6.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

python_glmnet-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

python_glmnet-2.6.1-cp312-cp312-macosx_14_0_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

python_glmnet-2.6.1-cp312-cp312-macosx_14_0_arm64.whl (935.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

python_glmnet-2.6.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

python_glmnet-2.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

python_glmnet-2.6.1-cp311-cp311-macosx_14_0_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

python_glmnet-2.6.1-cp311-cp311-macosx_14_0_arm64.whl (935.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

python_glmnet-2.6.1-cp310-cp310-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

python_glmnet-2.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

python_glmnet-2.6.1-cp310-cp310-macosx_14_0_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 14.0+ x86-64

python_glmnet-2.6.1-cp310-cp310-macosx_14_0_arm64.whl (935.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file python_glmnet-2.6.1.tar.gz.

File metadata

  • Download URL: python_glmnet-2.6.1.tar.gz
  • Upload date:
  • Size: 125.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for python_glmnet-2.6.1.tar.gz
Algorithm Hash digest
SHA256 6addc9e7cfe6c7df1e2e2f261098661b199d52458b558c394b7abd7e98be6e94
MD5 357e45d93a9b8f2d987affa6e7288538
BLAKE2b-256 19033a8be0259cc77001327c0aec31d572a4986e5e3239f34e0d5760a73bc47e

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aaaf590fd5c5c1b863cc37c75faf704dd164204b9335e1810eb81875276294a7
MD5 17a4d47bba0c03f1cfd0fbdbdc6c8d75
BLAKE2b-256 f5df57d2705963949e83c948cdc6d2859beaee780453db20dde520b9a9c535f3

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e178531829753bed49a7ba3e6f7ddf81f921b43c4326e3597abb0c6ca648c7f9
MD5 03cf35b928c253bfc4028cbee643f439
BLAKE2b-256 68d8324da86f9879e4d1289fbe6ce11edc7a6ebee0227ee23a6f675f1e676ef1

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp313-cp313-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp313-cp313-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 09c3e030d5ea6d099c4b63a701ad3223a1472f9354b50607aad21d6ef6406ae1
MD5 89705cf42efeb56d7570cb77defcd496
BLAKE2b-256 944510d83590866052f4998d72a4624cc18a537b41d048a8980e78c8aeebf6cf

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c9b98271f53b9189596ef38ba9528c28472e2400cb813afd08344b99b57042b6
MD5 517fecd0c8149089688c3f4450bea5f4
BLAKE2b-256 28edcd0e97b6040f8fe4f156f23a699beb9016bad212c38d5c53af0445be8a31

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5e3925e6a67f8b1f8d1823cd9e2d1d4ad63bab0471b0b1aa5db773151f10833e
MD5 cbadc630b87f7064e456d6311525cab4
BLAKE2b-256 20c09b1491ef91ecf9d604c10401b6dd455d9a9188e8b3f4f11903eefc59190a

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8c1aaee5f78f9dbdf3a06c6507f9d3ef59434f376d099f8a906afe4f6b17289
MD5 a7f2762090b062565968d0f7d459545a
BLAKE2b-256 990967e68ca7abd0717f0cd366a97fb0bbce8994aea06b86ca116b54d4e6478d

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 a038d6bed83a0ae7cfe1d7e41c03513b3276f546627b85e75f8116126699160f
MD5 e227d49f281568146cac3d6d19136ca0
BLAKE2b-256 80e829c39c94844fdf46241e5bbddda3f557a7cebac093bb292af0ff4fec69ec

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 672a79745f36f9226b7b82082f07457e45a03dfee915310412dbf1f29c3471db
MD5 3a4afdb48a54c1619da801f8781f62ff
BLAKE2b-256 ad190370b6c2bb5a513ad7a9b204be14214dea459ccc11dc44f6937925bd8fd9

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9c1d91b628ad4121b68b5d39bb460b46dd829ca419e01f697bfe67dc2fef405a
MD5 e90a18707b6a90e7c4ee6a888d225e66
BLAKE2b-256 0185a0a96e806cd9202898f0cbbad004fbced9a68c8bea14f3713838dff5bb52

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0da97e52535b0a09eab9ac0b81810287b2eb9471789386ccf89af8d6b9551c7d
MD5 8687879513f2d1515f9d2bce5db8afa4
BLAKE2b-256 a0db7b89c12a1739522ff66bf9ed663dfa297999ccc2f6d872795c25588cd18f

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 31896723bfe31c8a9363c04542b108b9ace942aeb68dcd40a10992eb71242afc
MD5 f2032046788a99d0350e4eec0940326b
BLAKE2b-256 25ea6a034a496aa1071d3ff0de4aef7e5e6c21e2b3dbac3345f85e62f6a3770c

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a67a21b4792ab353669178372049224533647834c0370dd7280b967ca1c53d4e
MD5 9469523f42ff245318d549dbfe56b6e1
BLAKE2b-256 7ee21a57ff47d41d484c800d0a8d72c4e16b45f38518e5bbe49533cf23ebf10b

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b66d3540a391ae46a12de0e19c4a18cb5292d86aeb3899ada00eb11fee62a04e
MD5 97b92a6c735b1690a9b8d399c3abbf64
BLAKE2b-256 ab0dc432b43dce69323ecea9ee6545a62e889b781ec844f153ee4594b3b50de9

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e43eb4d38dfe64df836cd6c345791e23d064f1b1a336b84dc86cc4c3bbd153d
MD5 b9644f59109367093b44da44763105e0
BLAKE2b-256 b6e6d7f52671c92c6f569df8cb277ba71b791dc41e2582a098ef789f584293d8

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 a4934e9ee6f2f4f08fa9c10bea6b47176cc8906d9a6cf8db9f6270436209b419
MD5 670adeeb28e836c496ec71ddd23bb722
BLAKE2b-256 94a4029bc5caf624e0de562eb13af70815e75e8cc2db17c270b6bcc337178e7c

See more details on using hashes here.

File details

Details for the file python_glmnet-2.6.1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for python_glmnet-2.6.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a5a78f93340a987fb1e8ce75e47bb842582a98712639de2ad842e5242dca3f20
MD5 4bba411f928ed9b859e51cdddf174f17
BLAKE2b-256 7368fbc06ec68133aaaec52ea836476deb056140c0605e1ce7d6ceef48c819ed

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