.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/manifold/plot_mds.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 JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_manifold_plot_mds.py: ========================= القياس متعدد الأبعاد ========================= توضيح لـ MDS المتري وغير المتري على بيانات ضوضائية مولدة. يتم إزاحة النقاط المعاد بناؤها باستخدام MDS المتري وغير المتري MDS قليلاً لتجنب التداخل. .. GENERATED FROM PYTHON SOURCE LINES 12-103 .. image-sg:: /auto_examples/manifold/images/sphx_glr_plot_mds_001.png :alt: plot mds :srcset: /auto_examples/manifold/images/sphx_glr_plot_mds_001.png :class: sphx-glr-single-img .. code-block:: Python # Authors: The scikit-learn developers # SPDX-License-Identifier: BSD-3-Clause import numpy as np from matplotlib import pyplot as plt from matplotlib.collections import LineCollection from sklearn import manifold from sklearn.decomposition import PCA from sklearn.metrics import euclidean_distances EPSILON = np.finfo(np.float32).eps n_samples = 20 seed = np.random.RandomState(seed=3) X_true = seed.randint(0, 20, 2 * n_samples).astype(float) X_true = X_true.reshape((n_samples, 2)) # توسيط البيانات X_true -= X_true.mean() similarities = euclidean_distances(X_true) # إضافة ضوضاء إلى أوجه التشابه noise = np.random.rand(n_samples, n_samples) noise = noise + noise.T noise[np.arange(noise.shape[0]), np.arange(noise.shape[0])] = 0 similarities += noise mds = manifold.MDS( n_components=2, max_iter=3000, eps=1e-9, random_state=seed, dissimilarity="precomputed", n_jobs=1, ) pos = mds.fit(similarities).embedding_ nmds = manifold.MDS( n_components=2, metric=False, max_iter=3000, eps=1e-12, dissimilarity="precomputed", random_state=seed, n_jobs=1, n_init=1, ) npos = nmds.fit_transform(similarities, init=pos) # إعادة قياس البيانات pos *= np.sqrt((X_true**2).sum()) / np.sqrt((pos**2).sum()) npos *= np.sqrt((X_true**2).sum()) / np.sqrt((npos**2).sum()) # تدوير البيانات clf = PCA(n_components=2) X_true = clf.fit_transform(X_true) pos = clf.fit_transform(pos) npos = clf.fit_transform(npos) fig = plt.figure(1) ax = plt.axes([0.0, 0.0, 1.0, 1.0]) s = 100 plt.scatter(X_true[:, 0], X_true[:, 1], color="navy", s=s, lw=0, label="الموضع الحقيقي") plt.scatter(pos[:, 0], pos[:, 1], color="turquoise", s=s, lw=0, label="MDS") plt.scatter(npos[:, 0], npos[:, 1], color="darkorange", s=s, lw=0, label="NMDS") plt.legend(scatterpoints=1, loc="best", shadow=False) similarities = similarities.max() / (similarities + EPSILON) * 100 np.fill_diagonal(similarities, 0) # رسم الحواف start_idx, end_idx = np.where(pos) # تسلسل من (*line0*, *line1*, *line2*)، حيث:: # linen = (x0, y0), (x1, y1), ... (xm, ym) segments = [ [X_true[i, :], X_true[j, :]] for i in range(len(pos)) for j in range(len(pos)) ] values = np.abs(similarities) lc = LineCollection( segments, zorder=0, cmap=plt.cm.Blues, norm=plt.Normalize(0, values.max()) ) lc.set_array(similarities.flatten()) lc.set_linewidths(np.full(len(segments), 0.5)) ax.add_collection(lc) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.235 seconds) .. _sphx_glr_download_auto_examples_manifold_plot_mds.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/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/manifold/plot_mds.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/manifold/plot_mds.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mds.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mds.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mds.zip ` .. include:: plot_mds.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_