.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/manifold/plot_manifold_sphere.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_manifold_sphere.py: ============================================= طرق تعلم متعدد الشعب على كرة مقطوعة ============================================= تطبيق مختلف تقنيات :ref:`متعدد الشعب` على مجموعة بيانات كروية. هنا يمكن للمرء أن يرى استخدام خفض الأبعاد من أجل اكتساب بعض الحدس بخصوص طرق تعلم متعدد الشعب. فيما يتعلق بمجموعة البيانات، يتم قطع القطبين من الكرة، بالإضافة إلى شريحة رقيقة على جانبها. هذا يتيح لتقنيات تعلم متعدد الشعب "فردها" أثناء إسقاطها على بُعدين. لمثال مماثل، حيث يتم تطبيق الطرق على مجموعة بيانات المنحنى S، انظر :ref:`sphx_glr_auto_examples_manifold_plot_compare_methods.py` لاحظ أن الغرض من :ref:`MDS ` هو إيجاد تمثيل منخفض الأبعاد للبيانات (هنا 2D) فيه المسافات تحترم جيدًا المسافات في الفضاء الأصلي عالي الأبعاد، على عكس خوارزميات تعلم متعدد الشعب الأخرى، فهي لا تسعى إلى تمثيل متماثل للبيانات في الفضاء منخفض الأبعاد. هنا تتطابق مشكلة متعدد الشعب بشكل كبير مع تمثيل خريطة مسطحة للأرض، كما هو الحال مع `إسقاط الخريطة `_ .. GENERATED FROM PYTHON SOURCE LINES 27-158 .. image-sg:: /auto_examples/manifold/images/sphx_glr_plot_manifold_sphere_001.png :alt: تعلم متعدد الشعب مع 1000 نقطة، 10 جار, LLE (0.061 sec), LTSA (0.98 sec), Hessian LLE (0.66 sec), Modified LLE (1.3 sec), Isomap (0.21 sec), MDS (0.73 sec), التضمين الطيفي (0.055 sec), t-SNE (3.2 sec) :srcset: /auto_examples/manifold/images/sphx_glr_plot_manifold_sphere_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none standard: 0.061 sec ltsa: 0.98 sec hessian: 0.66 sec modified: 1.3 sec ISO: 0.21 sec MDS: 0.73 sec Spectral Embedding: 0.055 sec t-SNE: 3.2 sec | .. code-block:: Python # Authors: The scikit-learn developers # SPDX-License-Identifier: BSD-3-Clause from time import time import matplotlib.pyplot as plt # Unused but required import for doing 3d projections with matplotlib < 3.2 import mpl_toolkits.mplot3d # noqa: F401 import numpy as np from matplotlib.ticker import NullFormatter from sklearn import manifold from sklearn.utils import check_random_state # متغيرات لتعلم متعدد الشعب. n_neighbors = 10 n_samples = 1000 # إنشاء الكرة. random_state = check_random_state(0) p = random_state.rand(n_samples) * (2 * np.pi - 0.55) t = random_state.rand(n_samples) * np.pi # قطع القطبين من الكرة. indices = (t < (np.pi - (np.pi / 8))) & (t > ((np.pi / 8))) colors = p[indices] x, y, z = ( np.sin(t[indices]) * np.cos(p[indices]), np.sin(t[indices]) * np.sin(p[indices]), np.cos(t[indices]), ) # رسم مجموعة البيانات. fig = plt.figure(figsize=(15, 8)) plt.suptitle( "تعلم متعدد الشعب مع %i نقطة، %i جار" % (1000, n_neighbors), fontsize=14 ) ax = fig.add_subplot(251, projection="3d") ax.scatter(x, y, z, c=p[indices], cmap=plt.cm.rainbow) ax.view_init(40, -10) sphere_data = np.array([x, y, z]).T # إجراء تعلم متعدد الشعب بالتضمين الخطي المحلي methods = ["standard", "ltsa", "hessian", "modified"] labels = ["LLE", "LTSA", "Hessian LLE", "Modified LLE"] for i, method in enumerate(methods): t0 = time() trans_data = ( manifold.LocallyLinearEmbedding( n_neighbors=n_neighbors, n_components=2, method=method, random_state=42 ) .fit_transform(sphere_data) .T ) t1 = time() print("%s: %.2g sec" % (methods[i], t1 - t0)) ax = fig.add_subplot(252 + i) plt.scatter(trans_data[0], trans_data[1], c=colors, cmap=plt.cm.rainbow) plt.title("%s (%.2g sec)" % (labels[i], t1 - t0)) ax.xaxis.set_major_formatter(NullFormatter()) ax.yaxis.set_major_formatter(NullFormatter()) plt.axis("tight") # إجراء تعلم متعدد الشعب باستخدام Isomap. t0 = time() trans_data = ( manifold.Isomap(n_neighbors=n_neighbors, n_components=2) .fit_transform(sphere_data) .T ) t1 = time() print("%s: %.2g sec" % ("ISO", t1 - t0)) ax = fig.add_subplot(257) plt.scatter(trans_data[0], trans_data[1], c=colors, cmap=plt.cm.rainbow) plt.title("%s (%.2g sec)" % ("Isomap", t1 - t0)) ax.xaxis.set_major_formatter(NullFormatter()) ax.yaxis.set_major_formatter(NullFormatter()) plt.axis("tight") # إجراء القياس متعدد الأبعاد. t0 = time() mds = manifold.MDS(2, max_iter=100, n_init=1, random_state=42) trans_data = mds.fit_transform(sphere_data).T t1 = time() print("MDS: %.2g sec" % (t1 - t0)) ax = fig.add_subplot(258) plt.scatter(trans_data[0], trans_data[1], c=colors, cmap=plt.cm.rainbow) plt.title("MDS (%.2g sec)" % (t1 - t0)) ax.xaxis.set_major_formatter(NullFormatter()) ax.yaxis.set_major_formatter(NullFormatter()) plt.axis("tight") # إجراء التضمين الطيفي. t0 = time() se = manifold.SpectralEmbedding( n_components=2, n_neighbors=n_neighbors, random_state=42 ) trans_data = se.fit_transform(sphere_data).T t1 = time() print("Spectral Embedding: %.2g sec" % (t1 - t0)) ax = fig.add_subplot(259) plt.scatter(trans_data[0], trans_data[1], c=colors, cmap=plt.cm.rainbow) plt.title("التضمين الطيفي (%.2g sec)" % (t1 - t0)) ax.xaxis.set_major_formatter(NullFormatter()) ax.yaxis.set_major_formatter(NullFormatter()) plt.axis("tight") # إجراء تضمين الجوار العشوائي الموزع على شكل حرف t. t0 = time() tsne = manifold.TSNE(n_components=2, random_state=0) trans_data = tsne.fit_transform(sphere_data).T t1 = time() print("t-SNE: %.2g sec" % (t1 - t0)) ax = fig.add_subplot(2, 5, 10) plt.scatter(trans_data[0], trans_data[1], c=colors, cmap=plt.cm.rainbow) plt.title("t-SNE (%.2g sec)" % (t1 - t0)) ax.xaxis.set_major_formatter(NullFormatter()) ax.yaxis.set_major_formatter(NullFormatter()) plt.axis("tight") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.049 seconds) .. _sphx_glr_download_auto_examples_manifold_plot_manifold_sphere.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_manifold_sphere.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_manifold_sphere.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_manifold_sphere.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_manifold_sphere.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_manifold_sphere.zip ` .. include:: plot_manifold_sphere.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_