| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Fork of python-glmnet with support for more recent Python versions. The package itself is not otherwise maintained; see glmstar for a more recent library based on a newer version of the underlying glmnet package.
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.
python-glmnet requires Python version >= 3.9, scikit-learn, numpy, and scipy. Installation from source or via pip requires a Fortran compiler.
conda install -c conda-forge glmnetpip install python-glmnetglmnet 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 installBy 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.
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)from glmnet import ElasticNet
m = ElasticNet()
m = m.fit(x, y)Predict:
p = m.predict(x)| Back | FazBrowse Home | New Git URL |