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.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.3 MB view details)

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

fastrvm-0.1.5-cp314-cp314-macosx_11_0_arm64.whl (223.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

fastrvm-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.3 MB view details)

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

fastrvm-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (223.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastrvm-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.3 MB view details)

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

fastrvm-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (222.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastrvm-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.3 MB view details)

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

fastrvm-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (222.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastrvm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.3 MB view details)

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

fastrvm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (221.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2237d795ff8a02d7796229cec0c9b9e3631157baba62cdadfd3254e3f9f040f
MD5 2a0d036241aff8b3faab69b26d032edf
BLAKE2b-256 225ff2748e6780db6e6af100854bd34a39d9d6e3231749eb09db176343cd8db0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad228cd6fc01f1ce4ba8025e03efc976dbfab6a3bd1ed254182495fbed752e37
MD5 7cd85726cda97f04276db9717aee2954
BLAKE2b-256 12b8e1d605ce88b598a688333abd6d89dbc79f8fecd861913c09edd13e38802c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 09268c9375e4317d2d596cf8c323dd57556a7ac925fda2a47f2fb69157e6721e
MD5 fd0ac5def6967832cd56f7bd1d003292
BLAKE2b-256 2704d06ccba680dd15800ae6f1713699f38c908e1c3ae459db94cdbed431ffe7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d141c1e53243b3efc4b1f3f9c404e4f6ccf98224905a1986280528dc34ff801
MD5 5b3bf6437c1bb490c87a67d2485011d5
BLAKE2b-256 895a7a9f51365dc4d90444d629aee3baff347797f81a0f39967351428539c656

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9d2b5a927c25de05057e6d62878213be992d83c6ebc09eceb438b577f51993d4
MD5 bca39d519d2d912ac1730dfb5d2100aa
BLAKE2b-256 d1de846a3376e7545a4d72ee3349dd71504c531c3b0990fba7da0d69f78b3435

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 925bcf61573d25008bd9ed6661021880754ccf63a9c0c81d00a19d01c2af75ce
MD5 0302c1b95da7391830c0d7f45715525b
BLAKE2b-256 a342a76870a18f0878254b24c3dab462b43f9fe1b924207671fb60db6ea8aa68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ebcd5c1ad8b7c0ac8e8c59b29ffec1274fa62b9fed90bbeb066b07c451da1c6e
MD5 50442918a08e5286e143fa9354096169
BLAKE2b-256 da2cf0511b7639c281a1e35120d7a7e8fe83c6130cfde48a60181e91c2f16c0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55b917df433c3a1197fbf35bb56fda3e5e2124e3303887339e705b0f96b5e6e9
MD5 e60c4dc83b4ebb1dfe660070b0f6cfeb
BLAKE2b-256 253a1cf16ffdd626c17a84d7356ffacde6f9291e6b110670681d75a09fd0b78c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 acf8e77940edbe274a2e0e5fa1e1a476347a7ca42b05ee93611e0be76e483d0c
MD5 36b4d514feb85b21fa34934023ffe102
BLAKE2b-256 13eb7f9e41fb43bba5485add3dfdcf6cf48b92e2a316baea1426dbbe65720ef2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastrvm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b37896b687900f843cb806dcf7f7ec3f10df9ff611c49cbdb9555cc8dc9593ce
MD5 c10151df352704608ec6bd797dfbd7b1
BLAKE2b-256 ca31eb0e0598bc93b4d194218cbad86e920607d173cd16d150b33335e5d09c1a

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