Cluster unlabeled data into k groups using Lloyd’s algorithm (k-means).
import numpy as np
from sklearn.cluster import KMeans
X = np.array([[1,2],[1,4],[1,0],
[10,2],[10,4],[10,0]])
kmeans = KMeans(n_clusters=2, n_init=10, random_state=0).fit(X)
print("Cluster Centers:\n", kmeans.cluster_centers_)
print("Labels:", kmeans.labels_.tolist())
Cluster Centers:
[[10. 2.]
[ 1. 2.]]
Labels: [1, 1, 1, 0, 0, 0]