/
githubmirror
/
scikit-learn
Обзор
Документация
Войти
/
githubmirror
/
scikit-learn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/cluster/plot_kmeans_plusplus.py
45 строк
1 KB
Adrin Jalali
MNT Add author/license note where missing and add the linter (#29477)
22 июл 2024, 23:05
Не верифицирован
22 июл 2024, 23:05
3e127a3
Код
Авторство
О чём код?
""" =========================================================== An example of K-Means++ initialization =========================================================== An example to show the output of the :func:`sklearn.cluster.kmeans_plusplus` function for generating initial seeds for clustering. K-Means++ is used as the default initialization for :ref:`k_means`. """ # Authors: The scikit-learn developers # SPDX-License-Identifier: BSD-3-Clause import matplotlib.pyplot as plt from sklearn.cluster import kmeans_plusplus from sklearn.datasets import make_blobs # Generate sample data 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] # Calculate seeds from k-means++ centers_init, indices = kmeans_plusplus(X, n_clusters=4, random_state=0) # Plot init seeds along side sample data 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()