Scalable sparse linear models in Python
Project description
⚡ 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sparsely-1.1.0.tar.gz.
File metadata
- Download URL: sparsely-1.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8ab83eb347f8703ef26e727ed40280ed5a35bc8452098d53db87c96ad047d4
|
|
| MD5 |
86c34f8a4b0b4dd89633a6f26bf4902f
|
|
| BLAKE2b-256 |
d1ee003bc29ed926fbd11cfa31bd4d91608488023c888da3d4cb23d3530ceba2
|
File details
Details for the file sparsely-1.1.0-py3-none-any.whl.
File metadata
- Download URL: sparsely-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1553f43d350ab06fa28c2becf5fe1adb490fa52c4027638126842449818a854
|
|
| MD5 |
6ff005c27ad55c588a853fba5d258170
|
|
| BLAKE2b-256 |
4ab9dde7636d18c609364e6ad929719dd687437b65f809eb29dd63f7137bbd5b
|