.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_trees/plot_04_iris.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_04_iris.py: Hybrid MST--GG on the Iris data =============================== On the four-dimensional Iris measurements the tree cuts separate *setosa* right away (a long edge), while *versicolor* and *virginica* touch and are split by the volume criterion. A minimal cluster size of ten samples keeps the volume criterion from splitting off a handful of border samples. The result is displayed by classical MDS of the scaled data. .. GENERATED FROM PYTHON SOURCE LINES 11-37 .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_04_iris_001.png :alt: species, hybrid MST-GG (96.7% correct) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_04_iris_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none tree only : 0.9666666666666667 tree + GG : 0.9666666666666667 ['global', 'volume'] | .. code-block:: Python import matplotlib.pyplot as plt from graphclust import HybridMSTGG, classical_mds from graphclust._utils import pairwise_distances from graphclust.datasets import load_iris, minmax_scale from graphclust.plotting import plot_partition from graphclust.validity import clustering_rate X, y = load_iris() # [snippet:iris] model = HybridMSTGG(max_clusters=3, lambda_=2.0, min_cluster_size=10).fit(X) print("tree only :", clustering_rate(y, model.tree_labels_)) print("tree + GG :", clustering_rate(y, model.labels_)) # [/snippet:iris] print([s["criterion"] for s in model.split_history_]) Y = classical_mds(pairwise_distances(minmax_scale(X)), 2) fig, axes = plt.subplots(1, 2, figsize=(10, 4.2)) plot_partition(Y, y, ax=axes[0], title="species") plot_partition(Y, model.labels_, ax=axes[1], title=f"hybrid MST-GG ({100 * clustering_rate(y, model.labels_):.1f}% correct)") 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.104 seconds) .. _sphx_glr_download_auto_examples_03_trees_plot_04_iris.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_04_iris.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_iris.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_iris.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_iris.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_