QUESTION 1 OF 10

How does K-means optimize its objective?

Reveal the answer and explore the explanation.

01
EasyCoreVisual

How does K-means optimize its objective?

Answer
Answer

Partitions observations into k groups to minimize within-cluster squared distances.

Practical example

Assign points to centroids and update centroids iteratively.

PythonRelated concept example
from sklearn.cluster import KMeans
X = [[0,0], [0,1], [8,8], [9,8]]
m = KMeans(n_clusters=2, n_init=10, random_state=42).fit(X)
print(m.cluster_centers_)

Cluster labels themselves are arbitrary.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As