.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/cluster/plot_mean_shift.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_cluster_plot_mean_shift.py: ============================================= عرض توضيحي لخوارزمية التجميع متوسط التحول ============================================= المرجع: دورين كومانيسيو وبيتر مير، "متوسط التحول: نهج قوي نحو تحليل مساحة الميزات". معاملات IEEE على تحليل الأنماط والذكاء الاصطناعي. 2002. ص 603-619. .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python # المؤلفون: مطوري سكايت-ليرن # معرف الترخيص-SPDX: BSD-3-Clause import numpy as np from sklearn.cluster import MeanShift, estimate_bandwidth from sklearn.datasets import make_blobs .. GENERATED FROM PYTHON SOURCE LINES 20-22 توليد بيانات العينة -------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python centers = [[1, 1], [-1, -1], [1, -1]] X, _ = make_blobs(n_samples=10000, centers=centers, cluster_std=0.6) .. GENERATED FROM PYTHON SOURCE LINES 26-28 حساب التجميع باستخدام MeanShift --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-42 .. code-block:: Python # يمكن الكشف عن عرض النطاق الترددي التالي تلقائيًا باستخدام bandwidth = estimate_bandwidth(X, quantile=0.2, n_samples=500) ms = MeanShift(bandwidth=bandwidth, bin_seeding=True) ms.fit(X) labels = ms.labels_ cluster_centers = ms.cluster_centers_ labels_unique = np.unique(labels) n_clusters_ = len(labels_unique) print("عدد التجمعات المقدرة: %d" % n_clusters_) .. rst-class:: sphx-glr-script-out .. code-block:: none عدد التجمعات المقدرة: 3 .. GENERATED FROM PYTHON SOURCE LINES 43-45 رسم النتيجة ----------- .. GENERATED FROM PYTHON SOURCE LINES 45-66 .. code-block:: Python import matplotlib.pyplot as plt plt.figure(1) plt.clf() colors = ["#dede00", "#377eb8", "#f781bf"] markers = ["x", "o", "^"] for k, col in zip(range(n_clusters_), colors): my_members = labels == k cluster_center = cluster_centers[k] plt.plot(X[my_members, 0], X[my_members, 1], markers[k], color=col) plt.plot( cluster_center[0], cluster_center[1], markers[k], markerfacecolor=col, markeredgecolor="k", markersize=14, ) plt.title("Estimated number of clusters: %d" % n_clusters_) plt.show() .. image-sg:: /auto_examples/cluster/images/sphx_glr_plot_mean_shift_001.png :alt: Estimated number of clusters: 3 :srcset: /auto_examples/cluster/images/sphx_glr_plot_mean_shift_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.447 seconds) .. _sphx_glr_download_auto_examples_cluster_plot_mean_shift.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/cluster/plot_mean_shift.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/cluster/plot_mean_shift.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mean_shift.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mean_shift.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mean_shift.zip ` .. include:: plot_mean_shift.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_