Skip to content

Python implementation of elastic-net regularized generalized linear models

License

Notifications You must be signed in to change notification settings

evadyer/pyglmnet

 
 

Repository files navigation

pyglmnet

A python implementation of elastic-net regularized generalized linear models

License Travis Coverage Status Gitter

We follow the same approach and notations as in Friedman, J., Hastie, T., & Tibshirani, R. (2010) and the accompanying widely popular R package.

Installation

Clone the repository.

$ git clone http://github.com/pavanramkumar/pyglmnet

Install pyglmnet using setup.py as follows

$ python setup.py develop install

Getting Started

Here is an example on how to use GLM class.

import numpy as np
import scipy.sparse as sps
from sklearn.preprocessing import StandardScaler
from pyglmnet import GLM

# create an instance of the GLM class
glm = GLM(distr='poisson', verbose=True, alpha=0.05)

n_samples, n_features = 10000, 100

# sample random coefficients
beta0 = np.random.normal(0.0, 1.0, 1)
beta = sps.rand(n_features, 1, 0.1)
beta = np.array(beta.todense())

# simulate training data
Xr = np.random.normal(0.0, 1.0, [n_samples, n_features])
yr = glm.simulate(beta0, beta, Xr)

# simulate testing data
Xt = np.random.normal(0.0, 1.0, [n_samples, n_features])
yt = glm.simulate(beta0, beta, Xt)

# fit the model on the training data
scaler = StandardScaler().fit(Xr)
glm.fit(scaler.transform(Xr), yr)

# predict using fitted model on the test data
yhat = glm.predict(scaler.transform(Xt))

More pyglmnet examples and use cases

Tutorial

Here is an extensive tutorial on GLMs with optimization and pseudo-code.

How to contribute?

We welcome pull requests. Please see our developer documentation page for more details.

Author

Contributors

Acknowledgments

License

MIT License Copyright (c) 2016 Pavan Ramkumar

About

Python implementation of elastic-net regularized generalized linear models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 73.7%
  • TeX 21.7%
  • Makefile 4.6%