Skip to content

Commit

Permalink
Merge pull request #74 from lbluque/main
Browse files Browse the repository at this point in the history
Refactoring estimators to be fully scikit learn compliant
  • Loading branch information
qchempku2017 authored Mar 8, 2023
2 parents 2b29634 + 9eac628 commit 7ffdb5b
Show file tree
Hide file tree
Showing 35 changed files with 2,817 additions and 1,912 deletions.
49 changes: 0 additions & 49 deletions .github/ISSUE_TEMPLATE/code_review.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-dist
name: build

# Use this workflow to manually trigger a build for testing purposes.
# Download it from artifacts to test installation, or upload directly to PyPI.
Expand Down
124 changes: 0 additions & 124 deletions .github/workflows/release.yml

This file was deleted.

23 changes: 12 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: test

env:
scip-version: 8.0.0

on:
push:
branches:
Expand All @@ -11,31 +14,29 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
max-parallel: 10
matrix:
python_version: ["3.8", "3.9", "3.10"] # cvxopt install in python "3.11" fails
python_version: ["3.8", "3.9", "3.10", "3.11"] # cvxopt install in python "3.11" fails

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
wget --quiet --no-check-certificate https://scipopt.org/download/release/SCIPOptSuite-${{ env.scip-version }}-Linux-ubuntu.deb
sudo apt-get update && sudo apt install -y ./SCIPOptSuite-${{ env.scip-version }}-Linux-ubuntu.deb
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies and package
run: |
python -m pip install --upgrade pip
pip install cython
pip install .[tests,dev]
- name: Test with pytest
Expand Down
17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,14 @@ repos:
- --expand-star-imports
- --ignore-init-module-imports

# flake8 can not be configured in pytoml, so line lengths will cause many failures
#- repo: https://github.com/PyCQA/flake8
# rev: 5.0.4
# hooks:
# - id: flake8
# files: ^sparselm/
# language_version: python3
# additional_dependencies:
# - flake8-typing-imports==1.10.1
# - flake8-rst-docstrings==0.2.3
# - flake8-rst==0.8.0

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0 # pick a git hash / tag to point to
hooks:
- id: pydocstyle
files: ^sparselm/
files: ^src/sparselm/
args:
- --convention=google
- --add-ignore=D107

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
Expand Down
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,21 @@ Sparse Linear Regression Models
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/CederGroupHub/sparse-lm/main.svg)](https://results.pre-commit.ci/latest/github/CederGroupHub/sparse-lm/main)
[![pypi version](https://img.shields.io/pypi/v/sparse-lm?color=blue)](https://pypi.org/project/sparse-lm)

**sparse-lm** includes several regularized regression estimators that are absent in the
**sparse-lm** includes several (structured) sparse linear regression estimators that are absent in the
`sklearn.linear_model` module. The estimators in **sparse-lm** are designed to fit right into
[scikit-lean](https://scikit-learn.org/stable/index.html) by inheriting from their base
`LinearModel`. But the underlying optimization problem is expressed and solved by
leveraging [cvxpy](https://www.cvxpy.org/).
[scikit-lean](https://scikit-learn.org/stable/index.html), but the underlying optimization problem is expressed and
solved by leveraging [cvxpy](https://www.cvxpy.org/).

---------------------------------------------------------------------------------------

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
- Lasso, Group Lasso, Overlap Group Lasso, Sparse Group Lasso & Ridged 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
-----
Basic 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**:

Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ API Documentation
:maxdepth: 2

sparselm.model
sparselm.stepwise
sparselm.model_selection
sparselm.tools
74 changes: 74 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Contributing
============

We welcome all forms of contribution, please consider contributing in any way you can!

Bugs, issues, input, and questions
----------------------------------
Please use the
`issue tracker <https://github.com/CederGroupHub/sparse-lm/issues>`_ to share any
of the following:

- Bugs
- Issues
- Questions
- Feature requests
- Ideas
- Input

Having these reported and saved in the issue tracker is very helpful to make
sure that they are properly addressed. Please make sure to be as descriptive
and neat as possible when opening up an issue.

Developing guidelines
---------------------
If you have written code or want to start writing new code that you think will improve **sparse-lm** then please follow
the steps below to make a contribution.

* All code should have unit tests.
* Code should be well documented following `google style <https://google.github.io/styleguide/pyguide.html>`_ docstrings.
* All code should pass the pre-commit hook. The code follows the `black code style <https://black.readthedocs.io/en/stable/>`_.
* Estimators should follow scikit-learn's `developing estimator guidelines <https://scikit-learn.org/stable/developers/develop.html>`_.

Adding code contributions
-------------------------

#. If you are contributing for the first time:

* *Fork* the repository and then *clone* your fork to your local workspace.
* Make sure to add the *upstream* repository as a remote::

git remote add upstream https://github.com/CederGroupHub/sparse-lm.git

* You should always keep your ``main`` branch or any feature branch up to date
with the upstream repository ``main`` branch. Be good about doing *fast forward*
merges of the upstream ``main`` into your fork branches while developing.

#. In order to have changes available without having to re-install the package:

* Install the package in *editable* mode::

pip install -e .

#. To develop your contributions you are free to do so in your *main* branch or any feature
branch in your fork.

* We recommend to only your forks *main* branch for short/easy fixes and additions.
* For more complex features, try to use a feature branch with a descriptive name.
* For very complex feautres feel free to open up a PR even before your contribution is finished with
[WIP] in its name, and optionally mark it as a *draft*.

#. While developing we recommend you use the pre-commit hook that is setup to ensure that your
code will satisfy all lint, documentation and black requirements. To do so install pre-commit, and run
in your clones top directory::

pre-commit install

* All code should use `google style <https://google.github.io/styleguide/pyguide.html>`_ docstrings
and `black <https://black.readthedocs.io/en/stable/?badge=stable>`_ style formatting.

#. Make sure to test your contribution and write unit tests for any new features. All tests should go in the
``sparse-lm\tests`` directory. The CI will run tests upon opening a PR, but running them locally will help find
problems before::

pytests tests
5 changes: 5 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Examples
========

.. note::
Under construction...
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ to run tests must be installed::

Then run the tests using::

pytest
pytest tests
1 change: 1 addition & 0 deletions docs/license.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
=======
License
=======

Expand Down
Loading

0 comments on commit 7ffdb5b

Please sign in to comment.