.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/cluster/plot_kmeans_plusplus.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_kmeans_plusplus.py: =============================== مثال على التهيئة K-Means++ =============================== مثال لإظار ناتج دالة :func:`sklearn.cluster.kmeans_plusplus` لإنشاء بذور أولية للتجميع. يتم استخدام K-Means++ كتهيئة افتراضية لـ :ref:`k_means`. .. GENERATED FROM PYTHON SOURCE LINES 11-43 .. image-sg:: /auto_examples/cluster/images/sphx_glr_plot_kmeans_plusplus_001.png :alt: K-Means++ Initialization :srcset: /auto_examples/cluster/images/sphx_glr_plot_kmeans_plusplus_001.png :class: sphx-glr-single-img .. code-block:: Python # المؤلفون: مطوري سكايلرن # معرف رخصة SPDX: BSD-3-Clause import matplotlib.pyplot as plt from sklearn.cluster import kmeans_plusplus from sklearn.datasets import make_blobs # توليد بيانات العينة n_samples = 4000 n_components = 4 X, y_true = make_blobs( n_samples=n_samples, centers=n_components, cluster_std=0.60, random_state=0 ) X = X[:, ::-1] # حساب البذور من k-means++ centers_init, indices = kmeans_plusplus(X, n_clusters=4, random_state=0) # رسم البذور الأولية بجانب بيانات العينة plt.figure(1) colors = ["#4EACC5", "#FF9C34", "#4E9A06", "m"] for k, col in enumerate(colors): cluster_data = y_true == k plt.scatter(X[cluster_data, 0], X[cluster_data, 1], c=col, marker=".", s=10) plt.scatter(centers_init[:, 0], centers_init[:, 1], c="b", s=50) plt.title("K-Means++ Initialization") plt.xticks([]) plt.yticks([]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.068 seconds) .. _sphx_glr_download_auto_examples_cluster_plot_kmeans_plusplus.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_kmeans_plusplus.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_kmeans_plusplus.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_kmeans_plusplus.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_kmeans_plusplus.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_kmeans_plusplus.zip ` .. include:: plot_kmeans_plusplus.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_