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 the accelerated RVM training algorithm described in [3] 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.

Limitations of the RVM

While powerful and often very sparse, the RVM can be viewed as a finite, data-dependent Gaussian process (GP): the kernel is a weighted sum of basis functions centred on the training inputs (see Rasmussen and Williams, 2006, chapter 6.6). Because the prior then depends on the observed inputs and the kernel is degenerate (finite rank), this departs from a strict Bayesian GP interpretation. With localized bases (e.g., RBFs), predictions far from any relevance vector can become spuriously overconfident: both the mean and the predictive variance may collapse toward zero (or the estimated noise level) even in clear extrapolation regions. This behavior is a modeling artifact of the degenerate kernel—computationally attractive, but it can harm uncertainty quantification in out-of-support areas.

Installation from Source

For development install from source:

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

Minimum build dependencies

  • CMake >= 3.18
  • Python >= 3.10 (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. Faul, A. C., & Tipping, M. E. (2002). Analysis of Sparse Bayesian Learning. In Advances in Neural Information Processing Systems 14 (NeurIPS 2002).

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

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 [3] 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.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

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

fastrvm-0.1.3-cp314-cp314-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

fastrvm-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

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

fastrvm-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastrvm-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

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

fastrvm-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastrvm-0.1.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastrvm-0.1.3-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.3-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file fastrvm-0.1.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6249a7156652288ee0d7927766ead90a5afbebfa3b43fc87cb5eaea5c92dc445
MD5 1db03f139aa896cb1275359ae9f6de69
BLAKE2b-256 d20632f8dcdee7c4857563c9ebc4eb0910e5158668849ce0c08eee16c81e4f87

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db5756795a7145fe1c2728f609a8378a04ab9306c5a8aa10d72add83a875fe90
MD5 0d8c46e9462e07b9b3d272f7eec03475
BLAKE2b-256 698133d6f29b8d02f42ecaf5f92bb00a5be484c13ee9eacc0f490b8459316237

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce50b84e2ff91788907e25b5875d215ddb4caa06a2ce09d65d453af343f07995
MD5 eb5e673a6fe297a4bf4f20a6d87f64fb
BLAKE2b-256 8a8819ee1feeef6a5220f20a2123cb32ad1ec641354d64d95992abe3786ce3a5

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c13c4fafdb6959dcea2135a0ee661b27cf42ab961d89e9fe67a00079522c3a3
MD5 7f8c95ef56161f5df44643692fff1b87
BLAKE2b-256 5067867d7751277de6f98364594ed195afb7cfe684b374dd1d738fe6a12e54ea

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c4d823777936f5b5f65dccc84827cdbbfd10244d595cd5bddda048eebc4ca4f9
MD5 98b4793b715c1d5c01255d44e9ac4796
BLAKE2b-256 d6f884d47f3c8e420f1b671652145c874f64a55fd652611536348084751cb780

See more details on using hashes here.

File details

Details for the file fastrvm-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbfb5fc6495a3423b87c6febb9f020eebf1dd6fdff31435035473598e3645489
MD5 de5ffdfacd5b78c8b2d7c1838f1b4a02
BLAKE2b-256 1cab0e58419aafe41b8ff4b3c81454764da34c65a76893fb3526fe096562a435

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26e01d856cf71126b8e2556abbd74c5bd9b98af42b80e1cd9a1ee86d33114365
MD5 8303a3b7b645f77eec50178597d3ae28
BLAKE2b-256 c382db0d6634d831f1dc1fc9558fae3858e577eb0d451048d52b4db64c2afb91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aaf26bdf24727d8dab4f0580e516f04aab018f982241ef4a5100577143adca6c
MD5 52a96dff888b1491128ca72d39a6ba53
BLAKE2b-256 01786660e002334ba319df7af810cf2a19be80b7ab5ac49822f43aaf5eb887db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 deaab5132a3fc8146159eabc7d39713953bc5333ff11bdb5de811e69872d1d33
MD5 cace0dd854ee2430c80dd40ce2c2f1a1
BLAKE2b-256 46a4c29cc545beb88558b7df9f7ee444f64d5abe7be2e0bbac68a8137b351ffe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bc80fe4dc12290b7814b86a0e16365fba70a46ec2a3a39ee8dea56d006e2890
MD5 53b789213cdcf937251f92ace5987af6
BLAKE2b-256 90aa2b4b115ececbd17716ffeb50513d1289f345d8e8eb525f9bf3dd1540355b

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