Package: skglm
A fast ⚡ and modular ⚒️ scikit-learn replacement for sparse GLMsskglmis a Python package that offersfast estimatorsfor sparse Generalized Linear Models (GLMs) that are100% compatible withscikit-learn. It ishighly flexibleand supports a wide range of GLMs.
You get to choose fromskglm's already-made estimators orcustomize your ownby combining the available datafits and penalties.Excited to have a tour onskglmdocumentation?Whyskglm?skglmis specifically conceived to solve sparse GLMs.
It supports many missing models inscikit-learnand ensures high performance.
There are several reasons to opt forskglmamong which:SpeedFast solvers able to tackle large datasets, either dense or sparse, with millions of featuresup to 100 times fasterthanscikit-learnModularityUser-friendly API that enablescomposing custom estimatorswith any combination of its existing datafits and penaltiesExtensibilityFlexible design that makes itsimple and easy to implement new datafits and penalties, a matter of few lines of codeCompatibilityEstimatorsfully compatible with thescikit-learnAPIand drop-in replacements of its GLM estimatorsGet started withskglmInstallingskglmskglmis available on PyPi. Run the following command to get the latest version of the packagepipinstall-UskglmIt is also available on conda-forge and can be installed using, for instance:condainstall-cconda-forgeskglmFirst steps withskglmOnce you installedskglm, you can run the following code snippet to fit a MCP Regression model on a toy dataset# import model to fitfromskglm.estimatorsimportMCPRegression# import util to create a toy datasetfromskglm.utils.dataimportmake_correlated_data# generate a toy datasetX,y,_=make_correlated_data(n_samples=10,n_features=100)# init and fit estimatorestimator=MCPRegression()estimator.fit(X,y)# print R²print(estimator.score(X,y))You can refer to the documentation to explore the list ofskglm's already-made estimators.Didn't find one that suits you? you can still compose your own.
Here is a code snippet that fits a MCP-regularized problem with Huber loss.# import datafit, penalty and GLM estimatorfromskglm.datafitsimportHuberfromskglm.penaltiesimportMCPenaltyfromskglm.estimatorsimportGeneralizedLinearEstimatorfromskglm.utils.dataimportmake_correlated_datafromskglm.solversimportAndersonCDX,y,_=make_correlated_data(n_samples=10,n_features=100)# create and fit GLM estimator with Huber loss and MCP penaltyestimator=GeneralizedLinearEstimator(datafit=Huber(delta=1.),penalty=MCPenalty(alpha=1e-2,gamma=3),solver=AndersonCD())estimator.fit(X,y)You will find detailed description on the supported datafits and penalties and how to combine them in the API section of the documentation.
You can also take our tutorial to learn how to create your own datafit and penalty.Contribute toskglmskglmis a continuous endeavour that relies on the community efforts to last and evolve. Your contribution is welcome and highly valuable. It can bebug report: you may encounter a bug while usingskglm. Don't hesitate to report it on theissue section.feature request: you may want to extend/add new features toskglm. You can usethe issue sectionto make suggestions.pull request: you may have fixed a bug, added a features, or even fixed a small typo in the documentation, ... you can submit apull requestand we will reach out to you asap.Citeskglmis the result of perseverant research. It is licensed underBSD 3-Clause. You are free to use it and if you do so, please cite@inproceedings{skglm,title={Beyond L1: Faster and better sparse models with skglm},author={Q. Bertrand and Q. Klopfenstein and P.-A. Bannier and G. Gidel and M. Massias},booktitle={NeurIPS},year={2022},}Useful linkslink to documentation:https://contrib.scikit-learn.org/skglm/link toskglmarXiv article:https://arxiv.org/pdf/2204.07826.pdf