We follow the same approach and notations as in Friedman, J., Hastie, T., & Tibshirani, R. (2010) and the accompanying widely popular R package.
Clone the repository.
$ git clone http://github.com/pavanramkumar/pyglmnet
Install pyglmnet
using setup.py
as follows
$ python setup.py develop install
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
Here is an extensive tutorial on GLMs with optimization and pseudo-code.
We welcome pull requests. Please see our developer documentation page for more details.
- Konrad Kording for funding and support
- Sara Solla for masterful GLM lectures
MIT License Copyright (c) 2016 Pavan Ramkumar