The K-means algorithm is so simple that we can quickly write it in 100 lines of code. The algorithm goes through the following steps to reach its goal:

  1. First, it picks up data points from the samples as initial centroids.
  2. Then, it assigns each sample to the closest centroid () using the following formula:
  3. Next, it updates the centroids so that they are at the center of the new clusters being led by the new cluster assignment.
  4. Repeat steps 2-3 until the cluster assignment remains unchanged or reaches the maximum number of iterations. ...

Get Hands-On Machine Learning with TensorFlow.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.