.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/_general/plot_intro_mlp_mmd.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples__general_plot_intro_mlp_mmd.py: ===================================================================== An introducing example to clustering with an MLP and the MMD GEMINI ===================================================================== We show in this example how to use the `gemclus.mlp.MLPMMD` to fit a simple mixture of Gaussian distributions. The architecture here is a two-layer neural network trained with the MMD GEMINI, an objective equivalent to kernel KMeans. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: Python from matplotlib import pyplot as plt from sklearn import datasets from gemclus.mlp import MLPMMD .. GENERATED FROM PYTHON SOURCE LINES 18-20 Generate data ------------- .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python X, y = datasets.make_blobs(centers=3, cluster_std=0.5, n_samples=200, random_state=0) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Create the MLP clustering model and fit it ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python clf = MLPMMD(random_state=0, ovo=True) clf.fit(X) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/circleci/.local/lib/python3.10/site-packages/sklearn/base.py:474: FutureWarning: `BaseEstimator._validate_data` is deprecated in 1.6 and will be removed in 1.7. Use `sklearn.utils.validation.validate_data` instead. This function becomes public and is part of the scikit-learn developer API. warnings.warn( .. raw:: html
MLPMMD(ovo=True, random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 34-36 Plot the final clustering ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-57 .. code-block:: Python y_pred = clf.predict(X) X_0 = X[y_pred == 0] X_1 = X[y_pred == 1] X_2 = X[y_pred == 2] ax0 = plt.scatter(X_0[:, 0], X_0[:, 1], c='crimson', s=50) ax1 = plt.scatter(X_1[:, 0], X_1[:, 1], c='deepskyblue', s=50) ax2 = plt.scatter(X_2[:, 0], X_2[:, 1], c='darkgreen', s=50) leg = plt.legend([ax0, ax1, ax2], ['Cluster 0', 'Cluster 1', 'Cluster 2'], loc='upper left', fancybox=True, scatterpoints=1) leg.get_frame().set_alpha(0.5) plt.xlabel('Feature 1') plt.ylabel('Feature 2') plt.show() .. image-sg:: /auto_examples/_general/images/sphx_glr_plot_intro_mlp_mmd_001.png :alt: plot intro mlp mmd :srcset: /auto_examples/_general/images/sphx_glr_plot_intro_mlp_mmd_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.710 seconds) .. _sphx_glr_download_auto_examples__general_plot_intro_mlp_mmd.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_intro_mlp_mmd.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_intro_mlp_mmd.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_intro_mlp_mmd.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_