.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_gstm.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_plot_gstm.py: ================================================================================================ Example of decision boundary map for a mixture of Gaussian and low-degree Student distributions ================================================================================================ This example is a retake from the experiment in the original GEMINI paper where we want to find the true clusters in a mixture of Gaussian that incorporates a low-degree-of-freedom student t-distribution. Consequently, this distribution generates sample that may seem like outliers if we are to expect only Gaussian distribution. Unlike the paper, this example here is done with the `gemclus.linear.LinearWasserstein` instead of an MLP. .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: default import numpy as np from matplotlib import pyplot as plt from gemclus.data import gstm from gemclus.linear import LinearWasserstein .. GENERATED FROM PYTHON SOURCE LINES 20-23 Generate the data ----------------- .. GENERATED FROM PYTHON SOURCE LINES 25-26 Taking 200 samples, 1 degree of freedom and not-so-far apart means .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: default X, y = gstm(n=200, alpha=3, df=1, random_state=0) .. GENERATED FROM PYTHON SOURCE LINES 29-32 Train the model for clustering ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: default clf = LinearWasserstein(n_clusters=4, random_state=0, batch_size=50) y_pred = clf.fit_predict(X) .. GENERATED FROM PYTHON SOURCE LINES 39-41 Final Clustering ----------------- .. GENERATED FROM PYTHON SOURCE LINES 43-62 .. code-block:: default # Now, generate as well grid inputs to help drawing the decision boundary x_vals = np.linspace(-10, 10, num=50) y_vals = np.linspace(-10, 10, num=50) xx, yy = np.meshgrid(x_vals, y_vals) grid_inputs = np.c_[xx.ravel(), yy.ravel()] zz = clf.predict(grid_inputs).reshape((50, 50)) # Plot decision boundary with predictions on top plt.contourf(xx, yy, zz, alpha=0.5, cmap="Blues") plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap="Reds_r") plt.xlim(-10, 10) plt.ylim(-10, 10) plt.xlabel('Feature 1') plt.ylabel('Feature 2') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_gstm_001.png :alt: plot gstm :srcset: /auto_examples/images/sphx_glr_plot_gstm_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.913 seconds) .. _sphx_glr_download_auto_examples_plot_gstm.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gstm.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gstm.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_