ArticleslgStudy

computer science

K-medians clustering

K-medians clustering is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand K-medians clustering rather than just read about it. In short: K-medians clustering is a partitioning technique used in cluster analysis. It groups data into k clusters by minimizing the sum of distances—typically using the Manhattan (L1) distance—between data points and the median of their assigned clusters.

Key takeaways

  • K-medians clustering belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect K-medians clustering to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of K-medians clustering from memory before moving on to harder problems.

Reference excerpt

K-medians clustering is a partitioning technique used in cluster analysis. It groups data into k clusters by minimizing the sum of distances—typically using the Manhattan (L1) distance—between data points and the median of their assigned clusters. This method is especially robust to outliers and is well-suited for discrete or categorical data. It is a generalization of the geometric median or 1-median algorithm, defined for a single cluster. k-medians is a variation of k-means clustering where instead of calculating the mean for each cluster to determine its centroid, one instead calculates the median. This has the effect of minimizing error over all clusters with respect to the 1-norm distance metric, as opposed to the squared 2-norm distance metric (which k-means does). This relates directly to the k-median problem: Given a metric space ( V , d ) {\displaystyle (V,d)} and an integer k {\displaystyle k} , the problem asks to find a set of k centers C ⊆ V {\displaystyle C\subseteq V} so as to minimize the sum of the distances from every element in V {\displaystyle V} to the closest center, namely we want to minimize

∑ u ∈ V min v ∈ C d ( u , v ) {\displaystyle \sum _{u\in V}\min _{v\in C}d(u,v)}

The criterion function formulated in this way is sometimes a better criterion than that used in the k-means clustering algorithm, in which the sum of the squared distances is used. The sum of distances is widely used in applications such as the facility location problem. The proposed algorithm uses Lloyd-style iteration which alternates between an expectation (E) and maximization (M) step, making this an expectation–maximization algorithm. In the E step, all objects are assigned to their nearest median. In the M step, the medians are recomputed by using the median in each single dimension.

Medians and medioids The median is computed in each single dimension in the Manhattan-distance formulation of the k-medians problem, so the individual attributes will come from the dataset (or be an average of two values from the dataset). This makes the algorithm more reliable for discrete or even binary data sets. In contrast, the use of means or Euclidean-distance medians will not necessarily yield individual attributes from the dataset. Even with the Manhattan-distance formulation, the individual attributes may come from different instances in the dataset; thus, the resulting median may not be a member of the input dataset. This algorithm is often confused with the k-medoids algorithm. However, a medoid has to be an actual instance from the dataset, while for the multivariate Manhattan-distance median this only holds for single attribute values. The actual median can thus be a combination of multiple instances. For example, given the vectors (0,1), (1,0) and (2,2), the Manhattan-distance median is (1,1), which does not exist in the original data, and thus cannot be a medoid.

Comparison with related algorithms K-medians clustering is closely related to other partitional clustering techniques such as k-means and k-medoids, each differing primarily in how cluster centers are determined and the type of distance metric employed. These differences lead to distinct behaviors with respect to robustness, computational cost, and applicability to various data distributions. The k-means algorithm minimizes the sum of squared Euclidean distances between data points and their corresponding cluster mean (centroid). It uses the arithmetic mean as the cluster representative, which makes it sensitive to outliers and noise because the mean can be heavily influenced by extreme values. In contrast, k-medians minimizes the sum of absolute differences (typically using the Manhattan/L1 distance), selecting the median along each dimension as the cluster center. Because the median is resistant to extreme values, k-medians is generally more robust in the presence of outliers. K-medoids also emphasizes robustness, but instead of using computed medians or means, it selects actual data points (medoids) as cluster centers. This makes k-medoids particularly suitable for non-Euclidean or categorical data. However, because it involves evaluating pairwise dissimilarities and repeatedly searching for representative points, it tends to be more computationally intensive than both k-means and k-medians, especially on large datasets.

Software ELKI includes various k-means variants, including k-medians. FORTRAN kmedians GNU R includes k-medians in the "flexclust" package. Stata kmedians

See also Cluster analysis k-means Medoid Silhouette

References

Worked examples

Example 1 — a first encounter with K-medians clustering

Start with the simplest possible case. Write down what K-medians clustering claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to K-medians clustering before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about K-medians clustering ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of K-medians clustering

In research
K-medians clustering appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses K-medians clustering in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
K-medians clustering is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cluster analysis algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for K-medians clustering outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “K-medians clustering” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study K-medians clustering in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what K-medians clustering means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain K-medians clustering out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is K-medians clustering in simple terms?

K-medians clustering is a partitioning technique used in cluster analysis. It groups data into k clusters by minimizing the sum of distances—typically using the Manhattan (L1) distance—between data points and the median of their assigned clusters.

Why does K-medians clustering matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study K-medians clustering?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on K-medians clustering.

Tags

  • Cluster analysis algorithms

Keep exploring