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.2.2.post2.tar.gz (89.7 kB view hashes)

Uploaded Source

Built Distributions

python_glmnet-2.2.2.post2-cp311-cp311-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

python_glmnet-2.2.2.post2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_glmnet-2.2.2.post2-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

python_glmnet-2.2.2.post2-cp311-cp311-macosx_10_9_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

python_glmnet-2.2.2.post2-cp310-cp310-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

python_glmnet-2.2.2.post2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_glmnet-2.2.2.post2-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

python_glmnet-2.2.2.post2-cp310-cp310-macosx_10_9_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

python_glmnet-2.2.2.post2-cp39-cp39-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

python_glmnet-2.2.2.post2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_glmnet-2.2.2.post2-cp39-cp39-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

python_glmnet-2.2.2.post2-cp39-cp39-macosx_10_9_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page