PROJECTENGRAM

K-MEANS CLUSTERING

K-Means Clustering

Tags: #◇Computer Science #◇CSINTSY #◇K-Means Clustering #◇Problem Solving #◇M4


◇Overview

K-Means Clustering is an unsupervised machine learning algorithm designed to partition a dataset into kk distinct, non-overlapping groups (clusters) based on feature similarity. It is particularly effective with numerical features where distance metrics can be applied. The number of clusters kk is a hyperparameter that must be manually defined prior to running the algorithm.

Algorithm Steps:

  1. Decide the number of clusters, kk.
  2. Initialize kk random centroids.
  3. Assign each data point to the cluster of the nearest centroid (using Euclidean distance).
  4. Recompute the centroids by taking the mean of all points assigned to each cluster.
  5. Repeat steps 3 and 4 until convergence (i.e., until assignments no longer change).

Choosing kk:
A higher kk is not necessarily better. Strategies for selecting an appropriate kk include: Utilizing domain knowledge. The Elbow Method, where the model's Inertia is plotted against various kk values, and the "elbow" point is chosen as the optimal kk.

◇Important Formulas

Inertia (Within-Cluster Sum of Squares):
A metric to measure cluster quality (lower is better, meaning tighter clusters).
Inertia=∑i=1k∑x∈Ci(x−μi)2\text{Inertia} = \sum_{i=1}^{k} \sum_{x \in C_i} (x - \mu_i)^2
Where CiC_i is cluster ii and μi\mu_i is the centroid of CiC_i.

◇Worked Examples

Algorithm Walkthrough:
Imagine a dataset with numerical features for temperature and humidity. Initialize k=2k=2 random points in this 2D space. Calculate the Euclidean distance of all data points to these two centroids. Assign points to the closest centroid. Shift the centroids to the average position of their respective assigned points. Repeat the assignment and shifting until the centroids no longer move. The final groupings represent the clusters.

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

Which category of machine learning does K-Means Clustering belong to?

Q2

What is the primary role of the hyperparameter kk in the K-Means algorithm?

Q3

During the K-Means algorithm execution, how are data points assigned to clusters?

Q4

What does the "Inertia" (Within-Cluster Sum of Squares) metric measure in K-Means clustering?

Q5

How is the "Elbow Method" used to select the optimal number of clusters kk?

K-Means Clustering | PROJECT ENGRAM