.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_rvm_for_classification.py: ========================================================= RVM for classification ========================================================= Based on https://github.com/ctgk/PRML/blob/master/notebooks/ch07_Sparse_Kernel_Machines.ipynb .. image:: /auto_examples/images/sphx_glr_plot_rvm_for_classification_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/sklearn-rvm/envs/latest/lib/python3.7/site-packages/sklearn_rvm/em_rvm.py:679: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning. "avoid this warning.", FutureWarning) | .. code-block:: default print(__doc__) import matplotlib.pyplot as plt import numpy as np from sklearn_rvm import EMRVC def create_toy_data(): x0 = np.random.normal(size=100).reshape(-1, 2) - 1. x1 = np.random.normal(size=100).reshape(-1, 2) + 1. x = np.concatenate([x0, x1]) y = np.concatenate([np.zeros(50), np.ones(50)]).astype(np.int) return x, y x_train, y_train = create_toy_data() model = EMRVC(kernel="rbf") model.fit(x_train, y_train) x0, x1 = np.meshgrid(np.linspace(-4, 4, 100), np.linspace(-4, 4, 100)) x = np.array([x0, x1]).reshape(2, -1).T plt.scatter(x_train[:, 0], x_train[:, 1], s=40, c=y_train, marker="x") plt.scatter(model.relevance_vectors_[:, 0], model.relevance_vectors_[:, 1], s=100, facecolor="none", edgecolor="g") plt.contourf(x0, x1, model.predict_proba(x)[:, 1].reshape(100, 100), np.linspace(0, 1, 5), alpha=0.2) plt.colorbar() plt.xlim(-4, 4) plt.ylim(-4, 4) plt.gca().set_aspect("equal", adjustable="box") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.893 seconds) .. _sphx_glr_download_auto_examples_plot_rvm_for_classification.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_rvm_for_classification.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_rvm_for_classification.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_