Skip to main content

Sparse linear regression models

Project description

Sparse Linear Regression Models

test pre-commit.ci status pypi version

:warning: this package is currently largely lacking in unit-tests. Use at your own risk!

sparse-lm includes several regularized regression estimators that are absent in the sklearn.linear_model module. The estimators in sparse-lm are designed to fit right into scikit-lean by inheriting from their base LinearModel. But the underlying optimization problem is expressed and solved by leveraging cvxpy.


Available regression models

  • Ordinary Least Squares (sklearn may be a better option)
  • Lasso (sklearn may be a better option)
  • Group Lasso, Overlap Group Lasso & Sparse Group Lasso
  • Adaptive versions of Lasso, Group Lasso, Overlap Group Lasso, Sparse Group Lasso & Ridged Group Lasso.
  • Best Subset Selection, Ridged Best Subset, L0, L1L0 & L2L0 (all with optional grouping of parameters) (gurobi recommended for performance)

Installation

From pypi:

pip install sparse-lm

Usage

If you already use scikit-learn, using sparse-lm will be very easy. Just use any model like you would any linear model in scikit-learn:

import numpy as np
from sklearn.datasets import make_regression
from sklearn.model_selection import GridSearchCV
from src.sparselm import AdaptiveLasso

X, y = make_regression(n_samples=200, n_features=5000, random_state=0)
alasso = AdaptiveLasso(fit_intercept=False)
param_grid = {'alpha': np.logsppace(-7, -2)}

cvsearch = GridSearchCV(alasso, param_grid)
cvsearch.fit(X, y)
print(cvsearch.best_params_)

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

sparse-lm-0.3.0.tar.gz (228.1 kB view details)

Uploaded Source

File details

Details for the file sparse-lm-0.3.0.tar.gz.

File metadata

  • Download URL: sparse-lm-0.3.0.tar.gz
  • Upload date:
  • Size: 228.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for sparse-lm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 17ea8efbfcbf22ad00594225653f3d4b029b01ef9046d881dc39954d9f10cca3
MD5 a6c8caa153fb438c8039a0796bf913f4
BLAKE2b-256 fff1d949478e04702b3f0ee5ff5bd15b40f519124617f2850d55d226cbf8075a

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