.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_classical_maps/plot_01_distance_maps.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_06_classical_maps_plot_01_distance_maps.py: PCA, Sammon mapping and MDS =========================== The distance-based maps differ in which distances they care about. PCA (or classical MDS on Euclidean distances) preserves the large-scale variance, metric MDS minimizes the raw squared error of all distances, Sammon's mapping divides each error by the input distance and therefore favors local structure, and non-metric MDS only keeps the rank order of the dissimilarities. On the standardized Wine data all four give a similar picture with overlapping cultivars. .. GENERATED FROM PYTHON SOURCE LINES 13-38 .. image-sg:: /auto_examples/06_classical_maps/images/sphx_glr_plot_01_distance_maps_001.png :alt: PCA Sammon 0.147, T(10) 0.888, metric MDS Sammon 0.063, T(10) 0.918, Sammon mapping Sammon 0.062, T(10) 0.909, non-metric MDS Sammon 0.072, T(10) 0.916 :srcset: /auto_examples/06_classical_maps/images/sphx_glr_plot_01_distance_maps_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none PCA {'sammon_stress': 0.147, 'mds_stress': 0.128, 'residual_variance': 0.329, 'auc_rnx': 0.375, 'trustworthiness@10': 0.888, 'continuity@10': 0.941} metric MDS {'sammon_stress': 0.063, 'mds_stress': 0.051, 'residual_variance': 0.184, 'auc_rnx': 0.434, 'trustworthiness@10': 0.918, 'continuity@10': 0.945} Sammon mapping {'sammon_stress': 0.062, 'mds_stress': 0.053, 'residual_variance': 0.206, 'auc_rnx': 0.42, 'trustworthiness@10': 0.909, 'continuity@10': 0.94} non-metric MDS {'sammon_stress': 0.072, 'mds_stress': 0.057, 'residual_variance': 0.149, 'auc_rnx': 0.431, 'trustworthiness@10': 0.916, 'continuity@10': 0.945} | .. code-block:: Python import matplotlib.pyplot as plt from sklearn.decomposition import PCA from graphclust import MetricMDS, NonMetricMDS, SammonMapping, metrics from graphclust.datasets import load_wine from graphclust.plotting import plot_embedding X, y = load_wine() X = (X - X.mean(0)) / X.std(0) # [snippet:maps] maps = { "PCA": PCA(2).fit_transform(X), "metric MDS": MetricMDS(random_state=0).fit_transform(X), "Sammon mapping": SammonMapping().fit_transform(X), "non-metric MDS": NonMetricMDS(random_state=0).fit_transform(X), } # [/snippet:maps] fig, axes = plt.subplots(1, 4, figsize=(14, 3.6)) for ax, (name, Y) in zip(axes, maps.items()): q = metrics.mapping_quality(X, Y, k=(10,)) plot_embedding(Y, y, ax=ax, title=f"{name}\nSammon {q['sammon_stress']:.3f}, T(10) {q['trustworthiness@10']:.3f}") print(name, {k: round(v, 3) for k, v in q.items()}) plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.276 seconds) .. _sphx_glr_download_auto_examples_06_classical_maps_plot_01_distance_maps.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/06_classical_maps/plot_01_distance_maps.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_distance_maps.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_distance_maps.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_distance_maps.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_