.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_assessment/plot_02_quality_measures.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_05_assessment_plot_02_quality_measures.py: Measuring the quality of a map ============================== Distance-based measures (Sammon stress, metric MDS stress, residual variance) ask whether the map distances reproduce the input distances. Rank-based measures ask whether neighbors stay neighbors: *trustworthiness* penalizes samples that look close in the map but are not, *continuity* penalizes neighbors torn apart. Both are computed from the co-ranking matrix, which also yields the :math:`R_{NX}(K)` curve and its area (AUC), the summary used in most recent comparisons. On the swiss roll, PCA folds the roll (low trustworthiness), whereas Isomap with geodesic distances unrolls it. Note that the distance-based measures, computed against Euclidean input distances, punish the unrolling: they should be computed against geodesic distances when the aim is to unfold a manifold. .. GENERATED FROM PYTHON SOURCE LINES 17-52 .. image-sg:: /auto_examples/05_assessment/images/sphx_glr_plot_02_quality_measures_001.png :alt: co-ranking matrix of PCA (first 100 ranks), trustworthiness, continuity, $R_{NX}(K)$ :srcset: /auto_examples/05_assessment/images/sphx_glr_plot_02_quality_measures_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none PCA {'sammon_stress': 0.083, 'mds_stress': 0.081, 'residual_variance': 0.342, 'auc_rnx': 0.546, 'trustworthiness@10': 0.875, 'continuity@10': 0.993} Sammon {'sammon_stress': 0.056, 'mds_stress': 0.05, 'residual_variance': 0.272, 'auc_rnx': 0.569, 'trustworthiness@10': 0.889, 'continuity@10': 0.991} Isomap {'sammon_stress': 4.204, 'mds_stress': 3.082, 'residual_variance': 0.925, 'auc_rnx': 0.673, 'trustworthiness@10': 0.999, 'continuity@10': 0.999} | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from sklearn.decomposition import PCA from graphclust import Isomap, SammonMapping, metrics from graphclust.datasets import make_swiss_roll from graphclust.plotting import plot_quality_curves X, t = make_swiss_roll(800, random_state=0) maps = { "PCA": PCA(2).fit_transform(X), "Sammon": SammonMapping().fit_transform(X), "Isomap": Isomap(k=8).fit_transform(X), } ks = np.arange(1, 51) T, C, R = {}, {}, {} for name, Y in maps.items(): # [snippet:quality] Q = metrics.coranking_matrix(X, Y) T[name], C[name] = metrics.trustworthiness_continuity(X, Y, ks, Q=Q) R[name] = metrics.rnx_curve(Q=Q) print(name, {k: round(v, 3) for k, v in metrics.mapping_quality(X, Y, k=(10,)).items()}) # [/snippet:quality] fig, axes = plt.subplots(1, 4, figsize=(15, 3.6)) axes[0].imshow(np.log1p(metrics.coranking_matrix(X, maps["PCA"])[:100, :100]), cmap="Greys") axes[0].set_title("co-ranking matrix of PCA (first 100 ranks)") axes[0].set_xlabel("rank in the map") axes[0].set_ylabel("rank in the data") plot_quality_curves(T, k=ks, ax=axes[1], ylabel="trustworthiness", title="trustworthiness") plot_quality_curves(C, k=ks, ax=axes[2], ylabel="continuity", title="continuity") plot_quality_curves(R, ax=axes[3], ylabel=r"$R_{NX}(K)$", title=r"$R_{NX}(K)$", logx=True) axes[3].set_xlabel("K") plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.460 seconds) .. _sphx_glr_download_auto_examples_05_assessment_plot_02_quality_measures.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/05_assessment/plot_02_quality_measures.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_quality_measures.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_quality_measures.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_quality_measures.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_