K-Means is the most popular clustering method any learner should know. In this note, we will understand the idea of KMeans and how to use it with Scikit-learn. Besides that, we also learn about its variants (K-medois, K-modes, K-medians).
A simply basic steps of K-Means.
A gif illustrating the idea of K-Means algorithm. Source.
Using "Elbow" method to choose the number of clusters $k$.
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=10, random_state=0) # default k=8
kmeans.fit(X)
kmeans.predict(X)
# or
kmeans.fit_predict(X)
Some notable parameters (see full):