.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_neighborhoods/plot_01_jarvis_patrick.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_04_neighborhoods_plot_01_jarvis_patrick.py: Jarvis--Patrick clustering and its two integer parameters ========================================================= Jarvis--Patrick clustering links two samples when each is among the other's ``k`` nearest neighbors and they share at least ``l`` of them; clusters are the connected components. The method finds clusters of different density, but its crisp threshold makes the result jump with both parameters: the same data give six, five, three or four groups, and only some settings separate the outlier from the three clusters. .. GENERATED FROM PYTHON SOURCE LINES 12-32 .. image-sg:: /auto_examples/04_neighborhoods/images/sphx_glr_plot_01_jarvis_patrick_001.png :alt: k = 6, l = 2: 6 groups, 96%, k = 8, l = 4: 6 groups, 96%, k = 12, l = 6: 3 groups, 74%, k = 12, l = 8: 4 groups, 100% :srcset: /auto_examples/04_neighborhoods/images/sphx_glr_plot_01_jarvis_patrick_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none k=6 l=2: 6 groups, clustering rate 0.96 k=8 l=4: 6 groups, clustering rate 0.96 k=12 l=6: 3 groups, clustering rate 0.74 k=12 l=8: 4 groups, clustering rate 1.00 | .. code-block:: Python import matplotlib.pyplot as plt from graphclust import JarvisPatrick from graphclust.datasets import make_variety from graphclust.plotting import plot_partition from graphclust.validity import clustering_rate X, y = make_variety() fig, axes = plt.subplots(1, 4, figsize=(14, 3.7)) for ax, (k, l) in zip(axes, [(6, 2), (8, 4), (12, 6), (12, 8)]): # [snippet:jp] jp = JarvisPatrick(k=k, min_shared=l).fit(X) # [/snippet:jp] rate = clustering_rate(y, jp.labels_) plot_partition(X, jp.labels_, ax=ax, markers=False, title=f"k = {k}, l = {l}: {jp.n_clusters_} groups, {100 * rate:.0f}%") ax.set_xticks([]) ax.set_yticks([]) print(f"k={k} l={l}: {jp.n_clusters_} groups, clustering rate {rate:.2f}") plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.066 seconds) .. _sphx_glr_download_auto_examples_04_neighborhoods_plot_01_jarvis_patrick.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/04_neighborhoods/plot_01_jarvis_patrick.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_jarvis_patrick.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_jarvis_patrick.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_jarvis_patrick.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_