Skip to main content

Relevance Vector Machine in Python with a C++ Core

Project description

fastrvm

Build Wheels PyPI version Python Versions License

A fast and clean implementation of the Relevance Vector Machine (RVM).

fastrvm teaser

fastrvm implements Tipping's "sparse Bayesian learning" algorithm [2] in a high-performance C++ core and exposes scikit-learn-compatible Python wrappers for:

  • RVR — relevance vector regression
  • RVC — relevance vector classification

Key benefits

  • Fast training and prediction due to the greedy learning algorithm and a tuned C++ linear-algebra core (Armadillo + Einsmallen for optimization).
  • Sparse models that automatically select a small set of relevance vectors.
  • scikit-learn-compatible Python wrappers: plug into pipelines, grid search, and common tooling.

Quick Start

Install the latest release from PyPI (wheels are provided for Ubuntu and macOS, Windows requires building from source):

pip install fastrvm

Regression example (RVR):

from fastrvm import RVR
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score

X, y = make_regression(n_samples=500, n_features=50, noise=0.1, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

model = RVR(kernel='linear', fit_intercept=True, max_iter=2000)
model.fit(X_train, y_train)
print('R2:', r2_score(y_test, model.predict(X_test)))

Classification example (RVC)

from fastrvm import RVC
from sklearn.datasets import make_classification
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score

X, y = make_classification(n_samples=300, n_features=50, n_informative=10, random_state=0)
clf = make_pipeline(StandardScaler(), RVC(kernel='rbf', gamma='scale', n_jobs=-1))
scores = cross_val_score(clf, X, y, cv=5, scoring='accuracy')
print('5-fold accuracy:', scores.mean())

Notes on the Python API

  • Classes: RVR and RVC available from fastrvm.
  • Estimator API: implements scikit-learn conventions (fit, predict, etc.).
  • Kernel options: rbf, linear, poly, precomputed (scikit-learn-style names). Various kernel hyperparameters such as gamma, degree, and coef0 are supported.
  • Multiclass classification: For efficiency reasons RVC uses a one-vs-rest classifier for multiclass classification.

See docs/fastrvm.md for a short reference doc.

Installation from Source

For development install from source:

git clone https://github.com/brdav/fastrvm.git
cd fastrvm
git submodule update --init --recursive
python -m pip install -e '.[dev]'

Minimum build dependencies

  • CMake >= 3.18
  • Python >= 3.9 (development headers)
  • C++17-capable compiler (clang, gcc, or MSVC)
  • BLAS/LAPACK implementation (OpenBLAS, MKL, or Accelerate)

Note: Builds on Windows are untested in CI. You can attempt a Windows build but expect manual steps.

The C++ core (sparse Bayesian learning algorithm) can also be built independently:

cmake -S src/cpp -B build/cpp -DCMAKE_BUILD_TYPE=Release
cmake --build build/cpp --target sparsebayes -j

Citation

Key references:

  1. Tipping, M. E. (2001). Sparse Bayesian Learning and the Relevance Vector Machine. Journal of Machine Learning Research, 1, 211–244.

  2. Tipping, M. E. & Faul, A. C. (2003). Fast Marginal Likelihood Maximisation for Sparse Bayesian Models. Proceedings of the 4th International Workshop on Artificial Intelligence and Statistics (AISTATS / PMLR), pages 276–283, 2003.

This implementation follows the ideas and practical choices from the SparseBayes (v2.0) MATLAB package by Michael Tipping — see the SparseBayes v2.0 download page. Please cite [1] for the core algorithm and [2] for the marginal-likelihood acceleration where applicable.

License

MIT — see LICENSE for details.


Questions, feature requests, or issues? Open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastrvm-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastrvm-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastrvm-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastrvm-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fastrvm-0.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastrvm-0.1.1-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file fastrvm-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c2901fb1d5771b9cfe8c3f1a75ffe2a425a9426dab6169e27d373365eb1ee707
MD5 3da1fb3ac7c7ab8461dfd6da4428d959
BLAKE2b-256 686f7a22b5dc27294fdaa85a0b1c6616fd7d3f22bde179736d0ad1da78f0e4d1

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f03d89a2bd1425fc5da7327cd882f9d467052da479c733050f509c250e40f3e2
MD5 eb9fa7f12ac214aed86212304593b396
BLAKE2b-256 62a549fdf34b641645f080f5d71265fd8b2a5bf44f187a1f0688658822eb7c2e

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df66df621c56a3255761e5fd88831c4eba7b20972fa399764e680886b97670a0
MD5 73501da507a1f8ccf95b6494f587fa59
BLAKE2b-256 e3443a54f43ee3dcb884999b9e0bde0f4e6d6db7b14fd42a2f04ed0a80a503f7

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e82cbe5f9709a7600b54d9a50aaa31e1a6e2fa695676098f2334209123e5bac
MD5 c3dd9125fed94aadd027da05c98e734b
BLAKE2b-256 0274fee64a35f75db102e120c9fd8cda13f9fcf48d4698708d4a497b09e05648

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e94db613aef8cbc5e3d56869e690945f3009ca77cef1cf3ac2eaae1e5cf6a8a
MD5 301ae4982ff2ae5b5af1b092b5584e69
BLAKE2b-256 a4c635126592965f75a03e060c0df1f5993dca03b839c18c2077198e2ba30704

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f9207817a1d5d96c252d004e8340757c42a3bc0b4fad8e3afc950642f069ad9
MD5 ff52e3addafcedf60010c3cdcd62010d
BLAKE2b-256 f9f415378daf70b402967aeabfec495e025f6a66c131f0bd9560e3fb01785e83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page