|
| 1 | +# Yet another generalized linear model package |
| 2 | + |
| 3 | +`ya_glm` aims to give you a fast, easy to use and flexible package for fitting a wide variety of penalized *generalized linear models* (GLM). Existing packages (e.g. [sklearn](https://scikit-learn.org/stable/), [lightning](https://github.com/scikit-learn-contrib/lightning), [statsmodels](https://www.statsmodels.org/), [glmnet](https://glmnet.stanford.edu/articles/glmnet.html), [pyglmenet](https://github.com/glm-tools/pyglmnet)) accomplish the first two of these goals, but are not easy to customize and support a limited number GLM + penalty combinations. |
| 4 | + |
| 5 | + |
| 6 | + **Beware**: this is a preliminary release of the package; the documentation and testing may leave you wanting and the code may be subject to breaking changes in the near future. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +# Installation |
| 11 | +`ya_glm` can be installed via github |
| 12 | +``` |
| 13 | +git clone https://github.com/idc9/ya_glm.git |
| 14 | +python setup.py install |
| 15 | +``` |
| 16 | + |
| 17 | +To use the backend from [andersoncd](https://github.com/mathurinm/andersoncd) you have to install their package manually -- see their github page. |
| 18 | + |
| 19 | + |
| 20 | +# Example |
| 21 | + |
| 22 | +```python |
| 23 | +from sklearn.datasets import make_regression |
| 24 | + |
| 25 | +from ya_glm.backends.fista.LinearRegression import Lasso, LassoCV,\ |
| 26 | + RidgeCV, LassoENetCV, GroupLassoENetCV, FcpLLACV |
| 27 | + |
| 28 | +# sample some linear regression data |
| 29 | +X, y = make_regression(n_samples=100, n_features=20) |
| 30 | + |
| 31 | +# fit the Lasso penalized linear regression model we all known and love |
| 32 | +est = Lasso(pen_val=1).fit(X, y) |
| 33 | + |
| 34 | +# tune the Lasso penalty using cross-validation |
| 35 | +# just as in sklearn.linear_model.LassoCV we use a |
| 36 | +# path algorithm to make this fast and set the tuning |
| 37 | +# parameter sequence with a sensible default |
| 38 | +est_cv = LassoCV(cv_select_rule='1se').fit(X, y) |
| 39 | + |
| 40 | +# or you could have picked a different penalty! |
| 41 | +# est_cv = RidgeCV().fit(X, y) |
| 42 | +# est_cv = LassoENetCV().fit(X, y) |
| 43 | + |
| 44 | +# we support user specified groups! |
| 45 | +groups = [np.arange(10), np.arange(10, 20)] |
| 46 | +est_groups = GroupLassoENetCV(groups).fit(X, y) |
| 47 | + |
| 48 | + |
| 49 | +# folded concave penalty, tuned with cross-validation |
| 50 | +# and initialized from the LassoCV solution |
| 51 | +# see (Fan et al. 2014) for details |
| 52 | +est_concave_cv = FcpLLACV(init=est_cv, |
| 53 | + pen_func='scad').fit(X, y) |
| 54 | +``` |
| 55 | + |
| 56 | +Se the [docs/](docs/) folder for additional examples in jupyter notebooks. |
| 57 | + |
| 58 | + |
| 59 | +# Currently supported features |
| 60 | + |
| 61 | +We currently support the following loss functions |
| 62 | + |
| 63 | +- linear regression |
| 64 | +- logistic regression |
| 65 | +- linear regression with multiple responses |
| 66 | + |
| 67 | +and the following penalties |
| 68 | + |
| 69 | +- Lasso (optionally with weights) |
| 70 | +- Group Lasso with user specified groups |
| 71 | +- Elastic net |
| 72 | +- Ridge |
| 73 | +- Tikhonov |
| 74 | +- Nuclear norm |
| 75 | +- Row lasso (i.e. L1 to L2 norm) |
| 76 | +- Folded concave penalties (FCP) such as SCAD |
| 77 | + |
| 78 | +The FCP penalties are fit by applying the *local linear approximation* (LLA) algorithm to a "good enough" initializer such as the Lasso fit. See (Fan et al, 2014) for details. |
| 79 | + |
| 80 | +We also provided built in cross-validation (CV) for each of these penalties. For Lasso, Ridge and ElasticNet CV methods use faster path algorithms (as in sklearn.linear_model.LassoCV). Our CV function allow custom metrics and custom selection rules such as the '1se' rule from the glmnet package. |
| 81 | + |
| 82 | +We aim to add additional loss functions including poisson, multinomial, gamma, huber, and cox regression. |
| 83 | + |
| 84 | + |
| 85 | +# What we provide on the backend |
| 86 | + |
| 87 | + |
| 88 | +- Cross-validation support for |
| 89 | + |
| 90 | + - path algorithms with parallelization over folds |
| 91 | + - custom evaluation metrics |
| 92 | + - custom CV selection rule (e.g. the '1se' rule) |
| 93 | + - automatically generated tuning parameter sequence from the training data for both Lasso and concave penalties. This requires computing the largest reasonable penalty value for different combinations of loss + penalty. |
| 94 | + - see e.g. `ya_glm.GlmCV`, `ya_glm.fcp.GlmFcpCV` |
| 95 | + |
| 96 | +- A flexible and reasonably fast FISTA algorithm (Beck and Tebouule, 2009) for GLM loss + non-smooth penalty problems |
| 97 | + - see `ya_glm.opt` |
| 98 | + - this module is inspired by [pyunlocbox](https://github.com/epfl-lts2/pyunlocbox) and [lightning](https://github.com/scikit-learn-contrib/lightning) |
| 99 | + |
| 100 | + |
| 101 | +- Support for concave penalties such as SCAD |
| 102 | + - fit using the LLA algorithm (Zou and Li, 2008; Fan et al. 2014) |
| 103 | + - see `ya_glm.lla` |
| 104 | + - the LLA algorithm only needs you to provide a solver for GLM + weight Lasso problems |
| 105 | + |
| 106 | + |
| 107 | +- Support for customization |
| 108 | + - straightforward to swap in your favorite GLM solver |
| 109 | + - see `ya_glm.backends.celer` for an example |
| 110 | + - cross-validation tuning |
| 111 | + - monitor various metrics for cross-validation path |
| 112 | + |
| 113 | + |
| 114 | +# Help and Support |
| 115 | + |
| 116 | +Additional documentation, examples and code revisions are coming soon. |
| 117 | +For questions, issues or feature requests please reach out to Iain: |
| 118 | +idc9@cornell.edu. |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +## Contributing |
| 123 | + |
| 124 | +We welcome contributions to make this a stronger package: data examples, |
| 125 | +bug fixes, spelling errors, new features, etc. |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +# References |
| 131 | + |
| 132 | +Zou, H. and Li, R., 2008. [One-step sparse estimates in nonconcave penalized likelihood models](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2759727/). Annals of statistics, 36(4), p.1509. |
| 133 | + |
| 134 | +Beck, A. and Teboulle, M., 2009. [A fast iterative shrinkage-thresholding algorithm for linear inverse problems](https://epubs.siam.org/doi/pdf/10.1137/080716542?casa_token=cjyK5OxcbSoAAAAA:lQOp0YAVKIOv2-vgGUd_YrnZC9VhbgWvZgj4UPbgfw8I7NV44K82vbIu0oz2-xAACBz9k0Lclw). SIAM journal on imaging sciences, 2(1), pp.183-202. |
| 135 | + |
| 136 | + |
| 137 | +Fan, J., Xue, L. and Zou, H., 2014. [Strong oracle optimality of folded concave penalized estimation](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4295817/). Annals of statistics, 42(3), p.819. |
0 commit comments