.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/decomposition/plot_pca_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 JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_decomposition_plot_pca_iris.py: ========================================================= تحليل المكونات الرئيسية (PCA) على مجموعة بيانات Iris ========================================================= هذا المثال يوضح تقنية تحليل معروفة باسم تحليل المكونات الرئيسية (PCA) على `مجموعة بيانات Iris `_. تتكون هذه المجموعة من 4 خصائص: طول الكأس، وعرض الكأس، وطول البتلة، وعرض البتلة. نستخدم PCA لإسقاط هذا الفضاء المكون من 4 خصائص إلى فضاء ثلاثي الأبعاد. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. code-block:: Python # المؤلفون: مطوري scikit-learn # معرف رخصة SPDX: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 15-22 تحميل مجموعة بيانات Iris ------------------------ مجموعة بيانات Iris متوفرة مباشرة كجزء من scikit-learn. يمكن تحميلها باستخدام الدالة :func:`~sklearn.datasets.load_iris`. مع المعاملات الافتراضية، يتم إرجاع كائن :class:`~sklearn.utils.Bunch`، والذي يحتوي على البيانات، والقيم المستهدفة، وأسماء الخصائص، وأسماء الأهداف. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python from sklearn.datasets import load_iris iris = load_iris(as_frame=True) print(iris.keys()) .. rst-class:: sphx-glr-script-out .. code-block:: none dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename', 'data_module']) .. GENERATED FROM PYTHON SOURCE LINES 28-32 رسم بياني لأزواج الخصائص في مجموعة بيانات Iris --------------------------------------------- دعنا نرسم أولاً أزواج الخصائص في مجموعة بيانات Iris. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python import seaborn as sns # إعادة تسمية الفئات باستخدام أسماء الأهداف في مجموعة بيانات Iris iris.frame["target"] = iris.target_names[iris.target] _ = sns.pairplot(iris.frame, hue="target") .. image-sg:: /auto_examples/decomposition/images/sphx_glr_plot_pca_iris_001.png :alt: plot pca iris :srcset: /auto_examples/decomposition/images/sphx_glr_plot_pca_iris_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-57 كل نقطة بيانات على كل رسم بياني متفرق تشير إلى واحدة من زهور Iris الـ 150 في مجموعة البيانات، مع الإشارة إلى لونها إلى نوعها (Setosa، وVersicolor، وVirginica). يمكنك بالفعل ملاحظة نمط فيما يتعلق بنوع Setosa، والذي يمكن تحديده بسهولة بناءً على كأسها القصير والعريض. فقط بالنظر إلى هذين البعدين، طول وعرض الكأس، لا يزال هناك تداخل بين نوعي Versicolor وVirginica. يُظهر القطر التوزيع لكل خاصية. نلاحظ أن عرض البتلة وطول البتلة هما أكثر الخصائص تمييزًا للأنواع الثلاثة. رسم تمثيل PCA ------------------------- دعنا نطبق تحليل المكونات الرئيسية (PCA) على مجموعة بيانات Iris ثم نرسم زهور Iris عبر الأبعاد الثلاثة الأولى لـ PCA. سيسمح لنا ذلك بالتمييز بشكل أفضل بين الأنواع الثلاثة! .. GENERATED FROM PYTHON SOURCE LINES 57-98 .. code-block:: Python import matplotlib.pyplot as plt # استيراد غير مستخدم ولكنه مطلوب للقيام بالرسوم البيانية ثلاثية الأبعاد باستخدام matplotlib < 3.2 import mpl_toolkits.mplot3d # noqa: F401 from sklearn.decomposition import PCA fig = plt.figure(1, figsize=(8, 6)) ax = fig.add_subplot(111, projection="3d", elev=-150, azim=110) X_reduced = PCA(n_components=3).fit_transform(iris.data) scatter = ax.scatter( X_reduced[:, 0], X_reduced[:, 1], X_reduced[:, 2], c=iris.target, s=40, ) ax.set( title="First three PCA dimensions", xlabel="1st Eigenvector", ylabel="2nd Eigenvector", zlabel="3rd Eigenvector", ) ax.xaxis.set_ticklabels([]) ax.yaxis.set_ticklabels([]) ax.zaxis.set_ticklabels([]) # إضافة أسطورة legend1 = ax.legend( scatter.legend_elements()[0], iris.target_names.tolist(), loc="upper right", title="Classes", ) ax.add_artist(legend1) plt.show() .. image-sg:: /auto_examples/decomposition/images/sphx_glr_plot_pca_iris_002.png :alt: First three PCA dimensions :srcset: /auto_examples/decomposition/images/sphx_glr_plot_pca_iris_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 99-101 ستقوم PCA بإنشاء 3 خصائص جديدة تكون مزيجًا خطيًا من الخصائص الأصلية الـ 4. بالإضافة إلى ذلك، تُعظِّم هذه التحويلة التباين. مع هذا التحويل، نرى أنه يمكننا تحديد كل نوع باستخدام الخاصية الأولى فقط (أي، المتجه الذاتي الأول). .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.495 seconds) .. _sphx_glr_download_auto_examples_decomposition_plot_pca_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/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/decomposition/plot_pca_iris.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/decomposition/plot_pca_iris.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pca_iris.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pca_iris.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pca_iris.zip ` .. include:: plot_pca_iris.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_