.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_trees/plot_02_hybrid_mst_gg.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_03_trees_plot_02_hybrid_mst_gg.py: Hybrid MST--Gath--Geva clustering cuts the chain ================================================ The hybrid algorithm always splits the cluster with the largest hypervolume :math:`\sqrt{\det\mathbf{F}_i}`. If Zahn's criteria find an inconsistent edge in it, that edge goes; otherwise the edge whose removal gives the smallest total fuzzy hypervolume is cut. Two compact groups joined by a chain have a far larger volume than the groups and the chain separately, so the volume criterion breaks the chain. The crisp partition then initializes Gath--Geva clustering, which returns memberships and a Gaussian description of every cluster. .. GENERATED FROM PYTHON SOURCE LINES 14-45 .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_02_hybrid_mst_gg_001.png :alt: MST cut by the hybrid criterion, Gath--Geva memberships (contours 0.5, 0.7, 0.9) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_02_hybrid_mst_gg_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none global cut of cluster 0 volumes [0.0032 0.0231] volume cut of cluster 0 volumes [0.0088 0.0076] volume cut of cluster 2 volumes [0.0011 0.003 ] clustering rate: 0.9866666666666667 | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from graphclust import HybridMSTGG from graphclust.datasets import make_chainlink from graphclust.plotting import PALETTE, plot_partition from graphclust.validity import clustering_rate X, y = make_chainlink() # [snippet:hybrid] model = HybridMSTGG(max_clusters=4, lambda_=2.5, m=2.0).fit(X) for step in model.split_history_: print(step["criterion"], "cut of cluster", step["cluster"], "volumes", np.round(step["volumes"], 4)) print("clustering rate:", clustering_rate(y, model.labels_)) # [/snippet:hybrid] fig, axes = plt.subplots(1, 2, figsize=(10, 4.3)) plot_partition(X, model.tree_labels_, ax=axes[0], title="MST cut by the hybrid criterion") Xs = (X - X.min(0)) / np.ptp(X, 0) gx, gy = np.meshgrid(np.linspace(-0.05, 1.05, 220), np.linspace(-0.05, 1.05, 220)) U = model.gath_geva_.predict_proba(np.c_[gx.ravel(), gy.ravel()]) for i in range(U.shape[1]): axes[1].contour(gx, gy, U[:, i].reshape(gx.shape), levels=[0.5, 0.7, 0.9], colors=PALETTE[i], linewidths=0.8) plot_partition(Xs, model.labels_, ax=axes[1], title="Gath--Geva memberships (contours 0.5, 0.7, 0.9)") axes[1].scatter(*model.cluster_centers_.T, marker="+", s=120, c="k") for ax in axes: ax.set_xticks([]) ax.set_yticks([]) plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.068 seconds) .. _sphx_glr_download_auto_examples_03_trees_plot_02_hybrid_mst_gg.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/graphclust/main?urlpath=lab/tree/notebooks/auto_examples/03_trees/plot_02_hybrid_mst_gg.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_hybrid_mst_gg.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_hybrid_mst_gg.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_hybrid_mst_gg.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_