Skip to main content

A fast and modular scikit-learn replacement for generalized linear models

Project description

skglm logo

A fast ⚡ and modular ⚒️ scikit-learn replacement for sparse GLMs

build License Downloads Downloads PyPI version

skglm is a Python package that offers fast estimators for sparse Generalized Linear Models (GLMs) that are 100% compatible with scikit-learn. It is highly flexible and supports a wide range of GLMs. You get to choose from skglm's already-made estimators or customize your own by combining the available datafits and penalties.

Excited to have a tour on skglm documentation?

Why skglm?

skglm is specifically conceived to solve sparse GLMs. It supports many missing models in scikit-learn and ensures high performance. There are several reasons to opt for skglm among which:

Speed Fast solvers able to tackle large datasets, either dense or sparse, with millions of features up to 100 times faster than scikit-learn
Modularity User-friendly API that enables composing custom estimators with any combination of its existing datafits and penalties
Extensibility Flexible design that makes it simple and easy to implement new datafits and penalties, a matter of few lines of code
Compatibility Estimators fully compatible with the scikit-learn API and drop-in replacements of its GLM estimators

Get started with skglm

Installing skglm

skglm is available on PyPi. Run the following command to get the latest version of the package

pip install -U skglm

It is also available on conda-forge and can be installed using, for instance:

conda install -c conda-forge skglm

First steps with skglm

Once you installed skglm, you can run the following code snippet to fit a MCP Regression model on a toy dataset

# import model to fit
from skglm.estimators import MCPRegression
# import util to create a toy dataset
from skglm.utils.data import make_correlated_data

# generate a toy dataset
X, y, _ = make_correlated_data(n_samples=10, n_features=100)

# init and fit estimator
estimator = MCPRegression()
estimator.fit(X, y)

# print R²
print(estimator.score(X, y))

You can refer to the documentation to explore the list of skglm'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 estimator
from skglm.datafits import Huber
from skglm.penalties import MCPenalty
from skglm.estimators import GeneralizedLinearEstimator

from skglm.utils.data import make_correlated_data
from skglm.solvers import AndersonCD

X, y, _ = make_correlated_data(n_samples=10, n_features=100)
# create and fit GLM estimator with Huber loss and MCP penalty
estimator = 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 to skglm

skglm is a continuous endeavour that relies on the community efforts to last and evolve. Your contribution is welcome and highly valuable. It can be

  • bug report: you may encounter a bug while using skglm. Don't hesitate to report it on the issue section.
  • feature request: you may want to extend/add new features to skglm. You can use the issue section to 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 a pull request and we will reach out to you asap.

Cite

skglm is the result of perseverant research. It is licensed under BSD 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 links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skglm-0.3.1.tar.gz (71.2 kB view details)

Uploaded Source

File details

Details for the file skglm-0.3.1.tar.gz.

File metadata

  • Download URL: skglm-0.3.1.tar.gz
  • Upload date:
  • Size: 71.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for skglm-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7cd08f2ce99c0b190d8d4daf8137d893f5da2dbaf16aaedcf69a2e3166292d58
MD5 c8bd90450e523cb2e38d5a509a7b3817
BLAKE2b-256 ef0b15acc0a3a6c312b3dae14a497ec550e2a0fbfd35fd4905f054d4f9d00749

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page