From Bayesian Behavior Lab

Jump to: navigation, search

Purpose: To compile the original Fortran code of GLMNET to use it in Python which contains the Poisson link function that many people and me use in the lab.


  • git
  • f2py (translator from fortran to python)
  • gfortran (fortrain compiler)
  • scikit-learn (for the example)

1) Get repository from github

2) change directory and compile

  • cd glmnet-python
  • python build

3) compile fortran code

  • cd glmnet/
  • f2py -c --fcompiler=gnu95 --f77flags='-fdefault-real-8' --f90flags='-fdefault-real-8' glmnet.pyf glmnet.f

4) test code by going to root of project

  • cd ..

and in IPython run this example to see if it works

  • from glmnet import ElasticNet
  • from cv import CVGlmNet
  • enet = ElasticNet(alpha=.1)
  • enet_cv = CVGlmNet(enet, n_folds=10, n_jobs=10)
  • from sklearn.datasets.samples_generator import make_regression
  • X, y = make_regression(n_samples=100, n_features=10, n_informative=10, random_state=0, noise=35)
  •, y)
  • plot
  • enet_cv.plot_oof_devs()
This page was last modified on 14 August 2014, at 19:09. This page has been accessed 247,833 times.