Skip to main content

CI Version

⚡ sparsely ⚡

sparsely is a sklearn-compatible Python module for sparse linear regression and classification. It uses an efficient cutting-plane algorithm to optimize feature selection, which scales to thousands of samples and features. This implementation follows Bertsimas & Van Parys (2017) for regression, and Bertsimas, Pauphilet & Van Parys (2021) for classification.

Full API documentation can be found here.

Quick start

You can install sparsely using pip as follows:

pip install sparsely

Here is a simple example of how use a sparsely estimator:

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sparsely import SparseLinearRegressor

X,y = make_regression(n_samples=1000, n_features=100, n_informative=10, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

estimator = SparseLinearRegressor(k=10)  # k is the max number of non-zero coefficients
estimator.fit(X_train, y_train)
print(estimator.score(X_test, y_test))

Development

Clone the repository using git:

git clone https://github.com/joshivanhoe/sparsely

Create a fresh virtual environment using venv or conda. Activate the environment and navigate to the cloned halfspace directory. Install a locally editable version of the package using pip:

pip install -e .

To check the installation has worked, you can run the tests (with coverage metrics) using pytest as follows:

pytest --cov=sparsely tests/

Contributions are welcome! To see our development priorities, refer to the open issues. Please submit a pull request with a clear description of the changes you've made.

Release files for sparsely 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sparsely 1.1.0
File Size Uploaded
sparsely-1.1.0.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sparsely 1.1.0
File Interpreter ABI Platform
sparsely-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / sparsely-1.1.0.tar.gz

Download URL sparsely-1.1.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3d8ab83eb347f8703ef26e727ed40280ed5a35bc8452098d53db87c96ad047d4
BLAKE2b-256 checksum
How to use checksums
d1ee003bc29ed926fbd11cfa31bd4d91608488023c888da3d4cb23d3530ceba2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / sparsely-1.1.0-py3-none-any.whl

Download URL sparsely-1.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1553f43d350ab06fa28c2becf5fe1adb490fa52c4027638126842449818a854
BLAKE2b-256 checksum
How to use checksums
4ab9dde7636d18c609364e6ad929719dd687437b65f809eb29dd63f7137bbd5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page