├── sklearn_rvm ├── tests │ ├── __init__.py │ ├── performance.py │ ├── test_regressor.py │ └── test_classifier.py ├── _version.py ├── __init__.py └── em_rvm.py ├── MANIFEST.in ├── requirements.txt ├── doc ├── sphinxext │ ├── MANIFEST.in │ └── github_link.py ├── complexity.rst ├── kernel.rst ├── logos │ ├── favicon.ico │ └── sklearn-rvm-logo-small.png ├── tips.rst ├── mathematics.rst ├── requirements.txt ├── themes │ └── scikit-learn-modern │ │ ├── images │ │ └── logo.png │ │ ├── theme.conf │ │ ├── search.html │ │ ├── nav.html │ │ ├── layout.html │ │ ├── javascript.html │ │ └── static │ │ ├── js │ │ ├── searchtools.js │ │ └── vendor │ │ │ └── bootstrap.min.js │ │ └── css │ │ └── theme.css ├── .readthedocs.yml ├── regression.rst ├── classification.rst ├── templates │ ├── function.rst │ ├── numpydoc_docstring.py │ └── class.rst ├── user_guide.rst ├── introduction.rst ├── api.rst ├── about.rst ├── install.rst ├── index.rst ├── make.bat ├── Makefile └── conf.py ├── environment.yml ├── examples ├── README.txt ├── simple_example.py ├── simple_example_precomputed.py ├── rvm_for_regression.py ├── plot_rvm_for_classification.py ├── plot_compare_rvr_ard.py ├── plot_compare_rvr_svr.py └── plot_iris_rvc.py ├── setup.cfg ├── .coveragerc ├── .readthedocs.yml ├── AUTHORS.rst ├── .travis.yml ├── .gitignore ├── README.rst ├── .circleci └── config.yml ├── LICENSE ├── setup.py └── CODE_OF_CONDUCT.md /sklearn_rvm/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | scikit-learn -------------------------------------------------------------------------------- /sklearn_rvm/_version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.1.1" 2 | -------------------------------------------------------------------------------- /doc/sphinxext/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include tests *.py 2 | include *.txt 3 | -------------------------------------------------------------------------------- /doc/complexity.rst: -------------------------------------------------------------------------------- 1 | .. _complexity: 2 | 3 | =========== 4 | Complexity 5 | =========== 6 | -------------------------------------------------------------------------------- /doc/kernel.rst: -------------------------------------------------------------------------------- 1 | .. _kernel: 2 | 3 | ================ 4 | Kernel Functions 5 | ================ 6 | -------------------------------------------------------------------------------- /doc/logos/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mind-the-Pineapple/sklearn-rvm/HEAD/doc/logos/favicon.ico -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: sklearn_rvm 2 | dependencies: 3 | - numpy 4 | - scipy 5 | - scikit-learn 6 | -------------------------------------------------------------------------------- /doc/tips.rst: -------------------------------------------------------------------------------- 1 | .. _tips: 2 | 3 | ===================== 4 | Tips on Practical Use 5 | ===================== 6 | -------------------------------------------------------------------------------- /examples/README.txt: -------------------------------------------------------------------------------- 1 | .. _general_examples: 2 | 3 | General examples 4 | ================ 5 | 6 | Introductory examples. 7 | -------------------------------------------------------------------------------- /doc/mathematics.rst: -------------------------------------------------------------------------------- 1 | .. _mathematics: 2 | 3 | ======================== 4 | Mathematical Formulation 5 | ======================== 6 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx==2.3.1 2 | sphinx-gallery 3 | sphinx_rtd_theme 4 | numpydoc 5 | sphinxcontrib-fulltoc 6 | scikit-learn -------------------------------------------------------------------------------- /doc/logos/sklearn-rvm-logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mind-the-Pineapple/sklearn-rvm/HEAD/doc/logos/sklearn-rvm-logo-small.png -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.rst 3 | 4 | [aliases] 5 | test = pytest 6 | 7 | [tool:pytest] 8 | addopts = --doctest-modules 9 | -------------------------------------------------------------------------------- /doc/themes/scikit-learn-modern/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mind-the-Pineapple/sklearn-rvm/HEAD/doc/themes/scikit-learn-modern/images/logo.png -------------------------------------------------------------------------------- /sklearn_rvm/__init__.py: -------------------------------------------------------------------------------- 1 | from .em_rvm import EMRVR, EMRVC 2 | 3 | from ._version import __version__ 4 | 5 | __all__ = ['EMRVR', 'EMRVC', '__version__'] 6 | -------------------------------------------------------------------------------- /doc/.readthedocs.yml: -------------------------------------------------------------------------------- 1 | formats: 2 | - none 3 | requirements_file: requirements.txt 4 | python: 5 | pip_install: true 6 | extra_requirements: 7 | - tests 8 | - docs -------------------------------------------------------------------------------- /doc/regression.rst: -------------------------------------------------------------------------------- 1 | .. _regression: 2 | 3 | =========== 4 | Regression 5 | =========== 6 | 7 | EMRVR is a class able to solve regression problems. 8 | 9 | * Present example on regression problem. -------------------------------------------------------------------------------- /doc/themes/scikit-learn-modern/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | pygments_style = default 4 | stylesheet = css/theme.css 5 | 6 | [options] 7 | google_analytics = true 8 | mathjax_path = 9 | -------------------------------------------------------------------------------- /doc/classification.rst: -------------------------------------------------------------------------------- 1 | .. _classification: 2 | 3 | =============== 4 | Classification 5 | =============== 6 | 7 | EMRVC is a class able to solve classification problems. 8 | 9 | * Present example on 2 class classification. 10 | 11 | * Present example on multiple class classification. -------------------------------------------------------------------------------- /doc/templates/function.rst: -------------------------------------------------------------------------------- 1 | :mod:`{{module}}`.{{objname}} 2 | {{ underline }}==================== 3 | 4 | .. currentmodule:: {{ module }} 5 | 6 | .. autofunction:: {{ objname }} 7 | 8 | .. include:: {{module}}.{{objname}}.examples 9 | 10 | .. raw:: html 11 | 12 |
13 | -------------------------------------------------------------------------------- /doc/templates/numpydoc_docstring.py: -------------------------------------------------------------------------------- 1 | {{index}} 2 | {{summary}} 3 | {{extended_summary}} 4 | {{parameters}} 5 | {{returns}} 6 | {{yields}} 7 | {{other_parameters}} 8 | {{attributes}} 9 | {{raises}} 10 | {{warns}} 11 | {{warnings}} 12 | {{see_also}} 13 | {{notes}} 14 | {{references}} 15 | {{examples}} 16 | {{methods}} 17 | -------------------------------------------------------------------------------- /doc/user_guide.rst: -------------------------------------------------------------------------------- 1 | .. title:: User guide: contents 2 | 3 | .. _user_guide: 4 | 5 | ========== 6 | User Guide 7 | ========== 8 | 9 | .. toctree:: 10 | :numbered: 11 | 12 | introduction.rst 13 | regression.rst 14 | classification.rst 15 | complexity.rst 16 | tips.rst 17 | kernel.rst 18 | mathematics.rst 19 | -------------------------------------------------------------------------------- /doc/introduction.rst: -------------------------------------------------------------------------------- 1 | .. _introduction: 2 | 3 | ============ 4 | Introduction 5 | ============ 6 | 7 | The **Relevance Vector Machines (RVMs)** are a set of supervised learning methods for regression and classification problems that only require a sparse kernel representation. 8 | 9 | Advantages of the RVM are: 10 | 11 | Disadvantages of the RVM are: 12 | -------------------------------------------------------------------------------- /doc/templates/class.rst: -------------------------------------------------------------------------------- 1 | :mod:`{{module}}`.{{objname}} 2 | {{ underline }}============== 3 | 4 | .. currentmodule:: {{ module }} 5 | 6 | .. autoclass:: {{ objname }} 7 | 8 | {% block methods %} 9 | .. automethod:: __init__ 10 | {% endblock %} 11 | 12 | .. include:: {{module}}.{{objname}}.examples 13 | 14 | .. raw:: html 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/api.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | sklearn-api API 3 | #################### 4 | 5 | This is the full API documentation of the `sklearn-rvm` toolbox. 6 | 7 | RVM using expectation maximization 8 | ============================================================== 9 | 10 | .. currentmodule:: sklearn_rvm 11 | 12 | .. autosummary:: 13 | :toctree: generated/ 14 | :template: class.rst 15 | 16 | em_rvm.EMRVR 17 | em_rvm.EMRVC 18 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | # Configuration for coverage.py 2 | 3 | [run] 4 | branch = True 5 | source = sklearn_rvm 6 | include = */sklearn_rvm/* 7 | omit = 8 | */setup.py 9 | 10 | [report] 11 | exclude_lines = 12 | pragma: no cover 13 | def __repr__ 14 | if self.debug: 15 | if settings.DEBUG 16 | raise AssertionError 17 | raise NotImplementedError 18 | if 0: 19 | if __name__ == .__main__.: 20 | if self.verbose: 21 | show_missing = True 22 | -------------------------------------------------------------------------------- /doc/themes/scikit-learn-modern/search.html: -------------------------------------------------------------------------------- 1 | {%- extends "basic/search.html" %} 2 | {% block extrahead %} 3 | 4 | 5 | 6 | 7 | 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /doc/about.rst: -------------------------------------------------------------------------------- 1 | About us 2 | ======== 3 | 4 | .. include:: ../AUTHORS.rst 5 | 6 | .. _citing-sklearn-rvm: 7 | 8 | Citing sklearn-rvm 9 | ------------------- 10 | 11 | If you use sklearn-rvm in a scientific publication, we would appreciate 12 | citations to the following paper:: 13 | 14 | @inproceedings{tipping2000relevance, 15 | title={The relevance vector machine}, 16 | author={Tipping, Michael E}, 17 | booktitle={Advances in neural information processing systems}, 18 | pages={652--658}, 19 | year={2000} 20 | } -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | configuration: doc/conf.py 11 | 12 | # Build documentation with MkDocs 13 | #mkdocs: 14 | # configuration: mkdocs.yml 15 | 16 | # Optionally set the version of Python and requirements required to build your docs 17 | python: 18 | version: 3.7 19 | system_packages: true 20 | install: 21 | - requirements: doc/requirements.txt 22 | # - requirements: requirements.txt 23 | - method: pip 24 | path: . 25 | -------------------------------------------------------------------------------- /examples/simple_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | ========================================================= 6 | Simple example 7 | ========================================================= 8 | """ 9 | print(__doc__) 10 | 11 | import numpy as np 12 | from sklearn_rvm import EMRVC 13 | 14 | # General a toy dataset:s it's just a straight line with some Gaussian noise: 15 | n_samples = 100 16 | np.random.seed(0) 17 | 18 | X = np.random.normal(size=n_samples) 19 | y = (X > 0).astype(np.float) 20 | 21 | X[X > 0] *= 4 22 | X += .3 * np.random.normal(size=n_samples) 23 | 24 | X = X[:, np.newaxis] 25 | 26 | # Fit the classifier 27 | clf = EMRVC(kernel="linear") 28 | clf.fit(X, y) 29 | 30 | print(clf.predict(X)) 31 | print(clf.predict_proba(X)) 32 | print(clf.score(X, y)) 33 | -------------------------------------------------------------------------------- /examples/simple_example_precomputed.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | ========================================================= 6 | Simple example precomputed 7 | =========================================================""" 8 | print(__doc__) 9 | 10 | import numpy as np 11 | from sklearn.metrics.pairwise import pairwise_kernels 12 | 13 | from sklearn_rvm import EMRVC 14 | 15 | # General a toy dataset:s it's just a straight line with some Gaussian noise: 16 | n_samples = 100 17 | np.random.seed(0) 18 | X = np.random.normal(size=n_samples) 19 | y = (X > 0).astype(np.float) 20 | X[X > 0] *= 4 21 | X += .3 * np.random.normal(size=n_samples) 22 | 23 | X = X[:, np.newaxis] 24 | 25 | K = pairwise_kernels(X) 26 | # Fit the classifier 27 | clf = EMRVC(kernel="precomputed") 28 | clf.fit(K, y) 29 | 30 | print(clf.predict(K)) 31 | print(clf.predict_proba(K)) 32 | print(clf.score(K, y)) 33 | -------------------------------------------------------------------------------- /sklearn_rvm/tests/performance.py: -------------------------------------------------------------------------------- 1 | # import timeit 2 | # 3 | # 4 | # # Time classification with the iris dataset. 5 | # 6 | # setup_c = """ 7 | # from sklearn.datasets import load_iris 8 | # from sklearn_rvm import EMRVC 9 | # iris = load_iris() 10 | # X = iris.data 11 | # y = iris.target 12 | # clf = EMRVC() 13 | # """ 14 | # 15 | # time = timeit.timeit("clf.fit(X, y)", setup=setup_c, number=10) 16 | # 17 | # print("10 runs of Iris classification fitting took {} seconds.".format(time)) 18 | # 19 | # # Time regression with the boston ds. 20 | # 21 | # setup_r = """ 22 | # from sklearn.datasets import load_boston 23 | # from sklearn_rvm import EMRVR 24 | # boston = load_boston() 25 | # X = boston.data 26 | # y = boston.target 27 | # clf = EMRVR() 28 | # """ 29 | # 30 | # time = timeit.timeit("clf.fit(X, y)", setup=setup_r, number=10) 31 | # 32 | # print("10 runs of boston refression fitting took {} seconds.".format(time)) -------------------------------------------------------------------------------- /sklearn_rvm/tests/test_regressor.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | from sklearn_rvm import EMRVR 4 | from sklearn.metrics.pairwise import pairwise_kernels 5 | from sklearn import datasets 6 | 7 | boston = datasets.load_boston() 8 | rng = np.random.RandomState(0) 9 | perm = rng.permutation(boston.target.size) 10 | boston.data = boston.data[perm] 11 | boston.target = boston.target[perm] 12 | 13 | def test_simple_fit_predict(): 14 | X = np.array([[0, 0], [2, 2]]) 15 | y = np.array([0.0, 2.5 ]) 16 | clf = EMRVR() 17 | X_test = np.array([[5,5]]) 18 | clf.fit(X,y) 19 | pred = clf.predict(X_test) 20 | assert pred != None 21 | 22 | def test_precomputed_fit_predict(): 23 | kernel = pairwise_kernels(boston.data, metric='linear') 24 | clf = EMRVR(kernel = "precomputed") 25 | clf.fit(kernel, boston.target) 26 | pred = clf.predict(kernel) 27 | assert pred.shape == boston.target.shape 28 | -------------------------------------------------------------------------------- /doc/install.rst: -------------------------------------------------------------------------------- 1 | ##################################### 2 | Installation sklearn-rvm 3 | ##################################### 4 | 5 | Prerequisites 6 | ============= 7 | 8 | The sklearn-rvm package requires the following dependencies: 9 | 10 | * numpy (>=1.11) 11 | * scipy (>=0.17) 12 | * scikit-learn (>=0.22) 13 | 14 | Installing the latest release 15 | ============================= 16 | 17 | sklearn-rvm is currently available on the PyPi's reporitories and you can 18 | install it via `pip`:: 19 | 20 | pip install -U sklearn-rvm 21 | 22 | 23 | If you prefer, you can clone it and run the setup.py file. Use the following 24 | commands to get a copy from Github and install all dependencies:: 25 | 26 | git clone https://github.com/Mind-the-Pineapple/sklearn-rvm.git 27 | cd sklearn-rvm 28 | pip install . 29 | 30 | Or install using pip and GitHub:: 31 | 32 | pip install -U git+https://github.com/Mind-the-Pineapple/sklearn-rvm.git -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | 2 | This project was initiated in October 2019 with the mission of creating a Relevance Vector Machine implementation in Python that would be fully compatible with the scikit-learn_ framework. The project was helmed by `Pedro Ferreira da Costa 3 |').appendTo(this.out); 148 | this.output = $('