topskill.dev
CoursesTracks
All courses/Machine Learning FundamentalsK-means
Clustering and other approaches
2 / 9
← Machine Learning Fundamentals
○What machine learning learns○Features and labels○Training and inference○Regression or classification○The machine learning process○Data quality and coverage○Representing data✦Module Quiz
○Linear regression○Try a tiny linear model○Logistic regression○Nearest neighbors○Decision trees○Random forests○Boosting○Naive Bayes○Support vector machines✦Module Quiz
○Clustering●K-means○Choosing and interpreting clusters○Principal component analysis○Neural networks and deep learning○Self-supervised learning○Transfer learning○Reinforcement learning✦Module Quiz
○Generalization and overfitting○Holding out evaluation data○Data leakage○Baselines○Bias and variance intuition○Reading learning curves✦Module Quiz
○Prediction errors and residuals○Measuring regression error○Squared error and large misses○The confusion matrix○Precision and recall○Try a held-out classifier✦Module Quiz
○Bias and limits○Monitoring and drift○Comparing models for a decision✦Module Quiz
Clustering and other approaches

K-means

K-means represents a dataset with kkk cluster centers, also called centroids. Here kkk is the chosen number of groups. It alternates between assigning examples to centers and updating those centers.

Begin with initial center positions. Assign each example to its nearest center. Then replace each center with the coordinate-wise mean of the examples assigned to it. Repeat the assignment and update steps until the centers or assignments stop changing substantially.

Read the panels from top to bottom. Filled circles are observations; crosses are centers. The numbered point 3 changes group after the first center update. The data points do not move: only their assignments and the center positions change.

For one feature, a center is an ordinary mean. For values 1, 2, and 3:

c=1+2+33=2c=\frac{1+2+3}{3}=2c=31+2+3​=2

Here ccc is the center's coordinate. With two features, calculate the average of each feature separately. A center can lie between observations and need not be an actual recorded example.

K-means seeks small squared distances from examples to their assigned centers. Each assignment or mean update cannot increase that objective in the standard algorithm, but the final solution can depend on the initial centers. Different starts can settle into different groupings. Repeated starts help search for a better result; they do not guarantee the best possible grouping.

Check your understanding

In an update step, do the recorded examples move toward their center?

Answer: No. The examples stay fixed; the center moves to their mean.

Fact 1
1 / 1
FACT 1

No. The examples stay fixed; the center moves to their mean.