Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI

on:
push:
branches: [ master, main ]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Ruff
run: |
python -m pip install --upgrade pip
python -m pip install ruff

- name: Run Ruff
run: |
ruff --version
ruff check .

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
pip-${{ runner.os }}-${{ matrix.python-version }}-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install coverage

- name: Run unit tests
run: |
python -m coverage run -m unittest

- name: Coverage report
run: |
python -m coverage report -m

# Removed Coveralls upload step
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# scikit-rvm

[![CI](https://github.com/JamesRitchie/scikit-rvm/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JamesRitchie/scikit-rvm/actions/workflows/ci.yml)

scikit-rvm is a Python module implementing the [Relevance Vector Machine](https://en.wikipedia.org/wiki/Relevance_vector_machine) (RVM)
machine learning technique using the [scikit-learn](https://scikit-learn.org/) API.

## Quickstart

With NumPy, SciPy and scikit-learn available in your environment, install with:

```bash
pip install https://github.com/JamesRitchie/scikit-rvm/archive/master.zip
```

Regression is done with the `RVR` class:

```python
>>> from skrvm import RVR
>>> X = [[0, 0], [2, 2]]
>>> y = [0.5, 2.5]
>>> clf = RVR(kernel='linear')
>>> clf.fit(X, y)
RVR(alpha=1e-06, beta=1e-06, beta_fixed=False, bias_used=True, coef0=0.0,
coef1=None, degree=3, kernel='linear', n_iter=3000,
threshold_alpha=1000000000.0, tol=0.001, verbose=False)
>>> clf.predict([[1, 1]])
array([1.49995187])
```

Classification is done with the `RVC` class:

```python
>>> from skrvm import RVC
>>> from sklearn.datasets import load_iris
>>> iris = load_iris()
>>> clf = RVC()
>>> clf.fit(iris.data, iris.target)
RVC(alpha=1e-06, beta=1e-06, beta_fixed=False, bias_used=True, coef0=0.0,
coef1=None, degree=3, kernel='rbf', n_iter=3000, n_iter_posterior=50,
threshold_alpha=1000000000.0, tol=0.001, verbose=False)
>>> clf.score(iris.data, iris.target)
0.98
```

## Theory

The RVM is a sparse Bayesian analogue to the Support Vector Machine, with a
number of advantages:

- Provides probabilistic estimates, as opposed to the SVM's point estimates.
- Typically provides a sparser solution than the SVM, which tends to have the
number of support vectors grow linearly with the size of the training set.
- Does not need a complexity parameter to be selected in order to avoid
overfitting.

However, it is more expensive to train than the SVM, although prediction is
faster and no cross-validation runs are required.

The RVM's original creator, Mike Tipping, provides a selection of papers offering
detailed insight into the formulation of the RVM (and sparse Bayesian learning
in general) on a [dedicated page](http://www.miketipping.com/sparsebayes.htm), along with a Matlab implementation.

Most of this implementation was written working from Section 7.2 of Christopher
M. Bishop's [Pattern Recognition and Machine Learning](http://research.microsoft.com/en-us/um/people/cmbishop/prml/).

## Contributors

- [James Ritchie](https://github.com/JamesRitchie)
- [Jonathan Feinberg](https://github.com/jonathf)

## Future Improvements

- Implement the fast Sequential Sparse Bayesian Learning Algorithm outlined in
Section 7.2.3 of [Pattern Recognition and Machine Learning](http://research.microsoft.com/en-us/um/people/cmbishop/prml/)
- Handle ill-conditioning errors more gracefully.
- Implement more kernel choices.
- Create more detailed examples with IPython notebooks.

95 changes: 0 additions & 95 deletions README.rst

This file was deleted.

49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[project]
name = "scikit-rvm"
version = "0.1.0a1"
description = "Relevance Vector Machine implementation using the scikit-learn API"
readme = { file = "README.md", content-type = "text/markdown" }
authors = [
{ name = "James Ritchie", email = "skrvm@james.jmsrt.ch" },
]
license = { text = "BSD" }
keywords = ["machine-learning", "rvm", "sparse", "bayesian", "scikit-learn"]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.10"
dependencies = [
"numpy>=2.0",
"scipy>=1.12",
"scikit-learn>=1.5",
]

[dependency-groups]
dev = [
"coverage>=7.10.3",
"ruff>=0.12.8",
]

[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
exclude = ["tests*"]

# Ruff configuration
[tool.ruff]
line-length = 100
src = ["skrvm", "tests"]
exclude = [
".venv",
"build",
"dist",
"__pycache__",
]

[tool.ruff.lint.isort]
known-first-party = ["skrvm"]
52 changes: 0 additions & 52 deletions setup.py

This file was deleted.

6 changes: 3 additions & 3 deletions skrvm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""skrvm implements RVM models."""

from .rvm import RVR, RVC
from .rvm import RVC, RVR

__all__ = ['RVR', 'RVC']
__all__ = ["RVR", "RVC"]

__version__ = '0.1.0a1'
__version__ = "0.1.0a1"
Loading