The Wayback Machine - https://web.archive.org/web/20241123052147/https://www.geeksforgeeks.org/k-means-vs-k-medoids-clustering/
Open In App

Difference between K means and K medoids Clustering

Last Updated : 18 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Clustering is the most basic form of data grouping in data analysis as well as in machine learning; the process involves putting the given set of objects into various groups. In which the objects in any single group will be much closer to one another than the objects belonging to other groups. Facilitating the process of clustering, there are several algorithms that are quite popular: K-Means and K-Medoids. However, these two terms are not the same, though they have some related aspects in their application and usage.

The main purpose of this article is to outline the major points of difference between K-Means and K-Medoids clustering algorithms.

What is K-Means Clustering?

K-Means is an iterative algorithm that assigns K clusters to a dataset where each cluster has a center that is the average of all the points situated in it, always referred to as the centroid. The steps involved in K-Means are:

  1. Initialization: Choose some points in K as initial centroids randomly.
  2. Assignment: Label every data point to the closest centroid of that cluster using the formula of the distance that squares.
  3. Update: The centroids need to be calculated again, and it is done by taking the average of all the points that belong to a particular cluster.
  4. Repeat: Make assignments multiple times and perform update actions until they do not alter anymore (this step is called convergence).

Advantages of K-Means

  • Simplicity: The advantage of K-Means is that it is simple to use and has a rather uncomplicated algorism.
  • Efficiency: It is effective in terms of time complexity and thus can easily work with large data sets.
  • Speed: generally converges quickly.

Disadvantages of K-Means

  • Sensitivity to Outliers: K-Means is also susceptible to noise and outliers, chiefly because of its reliance on means as the critical measure in binning assignments.
  • Shape Assumption: This tends to hold the distances by treating the clusters as spherical objects of equal sizes, which is not always true.
  • Initial Centroids: The selection of the first K centroids may differ, and this may lead to different clustering and hence inaccurate clustering.

What is K-Medoids Clustering?

K-Medoids, or Partitioning Around Medoids (PAM), is similar to the K-Means clustering method but requires the use of medians for the formation of subgroups. A medoid is a centroid that best represents the objects in a defined cluster. The steps in K-Medoids are:The steps in K-Medoids are:

  • Initialization: The first step in the selection process involves choosing K initial medoids at random.
  • Assignment: Within the DUHI scenario, assign each data point to the nearest medoid or a previously defined criterion distance.
  • Update: In order to do this, the choice of a new medoid to represent each cluster should be the one that would result in the smallest sum of the distances within the cluster.
  • Repeat: Cycle through the assignment and update steps, revolving until meeting the convergence.

Advantages of K-Medoids

  • Robustness to Outliers: Most often, medoids are less prone to outliers and noises than centroids.
  • Flexibility in Distance Metrics: Others can use any distance measurement, not limited to the Euclidean distance measurement, making it general for all data types.

Disadvantages of K-Medoids

  • Computationally Intensive: K-Medoids is relatively slower than K-Means due to its higher complexity when working with larger databases.
  • Complexity: It is also more difficult to implement and understand than K-Means, even though it is a more effective clustering method.

Key Differences Between K-Means and K-Medoids

Centroid vs. Medoid

  • K-Means: Uses the mean of the points in a cluster as the centroid, which may not be an actual data point.
  • K-Medoids: Uses actual data points as medoids, making it more interpretable.

Distance Measures

  • K-Means: Typically uses Euclidean distance, which may not be suitable for all data types.
  • K-Medoids: Can use any distance measure, providing more flexibility.

Sensitivity to Outliers

  • K-Means: Sensitive to outliers, as they can significantly affect the mean.
  • K-Medoids: More robust to outliers, as medoids are actual data points less influenced by extreme values.

Computational Complexity

  • K-Means: Generally faster and more efficient, making it suitable for very large datasets.
  • K-Medoids: Slower due to the need to evaluate all possible swaps, better for smaller datasets or when robustness is crucial.

Convergence

  • K-Means: Converges faster but may end up in local minima.
  • K-Medoids: More likely to find a global optimum but at a higher computational cost.

Difference between K means and K medoids Clustering

Aspect

K -Means Clustering

K-Medoids Clustering

Representation of Clusters

K-Means Clustering uses the mean of points (centroid) to represent a cluster.

It uses the most centrally located point (medoid) to represent a cluster.

Sensitivity to Outliers

Highly sensitive to outliers.

More robust to outliers.

Distance Metrics

K-Means primarily uses Euclidean distance.

Whereas it can use any distance metric.

Computational Efficiency

K-Means is generally faster and more efficient

It is slower due to the need to calculate all pairwise distances within clusters.

Cluster Shape Assumption

It assumes spherical clusters.

It does not make strong assumptions about cluster shapes.

Practical Considerations

When to Use K-Means

  • When dealing with large datasets.
  • When computational efficiency is a priority.
  • When the data is well-behaved and not heavily influenced by outliers.

When to Use K-Medoids

  • When robustness to outliers is important.
  • When the dataset is smaller and the flexibility of using different distance measures is beneficial.
  • When interpretability of cluster centers as actual data points is needed.

Conclusion

K-Means and K-Medoids are two significant clustering algorithms that are unique in their own way with their positive and negative aspects. Which of them to focus on depends on the concrete qualities of the data, how compute-intensive the task is, etc., and the extent to which the presence of outliers will impact the result. This means that, depending on the specific needs of the data scientist in question, he or she will be able to correctly choose the most appropriate method for the particular kind of clustering job that has to be accomplished.


Similar Reads

ML | K-Medoids clustering with solved example
K-Medoids (also called Partitioning Around Medoid) algorithm was proposed in 1987 by Kaufman and Rousseeuw. A medoid can be defined as a point in the cluster, whose dissimilarities with all the other points in the cluster are minimum. The dissimilarity of the medoid(Ci) and object(Pi) is calculated by using E = |Pi - Ci| The cost in K-Medoids algor
3 min read
Difference between K means and Hierarchical Clustering
k-means is method of cluster analysis using a pre-specified no. of clusters. It requires advance knowledge of 'K'. Hierarchical clustering also known as hierarchical cluster analysis (HCA) is also a method of cluster analysis which seeks to build a hierarchy of clusters without having fixed number of cluster. Main differences between K means and Hi
2 min read
Difference between CURE Clustering and DBSCAN Clustering
Clustering is a technique used in Unsupervised learning in which data samples are grouped into clusters on the basis of similarity in the inherent properties of the data sample. Clustering can also be defined as a technique of clubbing data items that are similar in some way. The data items belonging to the same clusters are similar to each other i
2 min read
Difference Between Agglomerative clustering and Divisive clustering
Hierarchical clustering is a popular unsupervised machine learning technique used to group similar data points into clusters based on their similarity or dissimilarity. It is called "hierarchical" because it creates a tree-like hierarchy of clusters, where each node represents a cluster that can be further divided into smaller sub-clusters. There a
5 min read
Analyzing Decision Tree and K-means Clustering using Iris dataset
Iris Dataset is one of best know datasets in pattern recognition literature. This dataset contains 3 classes of 50 instances each, where each class refers to a type of iris plant. One class is linearly separable from the other 2 the latter are NOT linearly separable from each other. Attribute Information:Sepal Length in cmSepal Width in cmPetal Len
5 min read
Analysis of test data using K-Means Clustering in Python
This article demonstrates an illustration of K-means clustering on a sample random data using open-cv library. Pre-requisites: Numpy, OpenCV, matplot-lib Let's first visualize test data with Multiple Features using matplot-lib tool. # importing required tools import numpy as np from matplotlib import pyplot as plt # creating two test data X = np.ra
2 min read
ML | Determine the optimal value of K in K-Means Clustering
Prerequisite: K-Means Clustering | IntroductionThere is a popular method known as elbow method which is used to determine the optimal value of K to perform the K-Means Clustering Algorithm. The basic idea behind this method is that it plots the various values of cost with changing k. As the value of K increases, there will be fewer elements in the
2 min read
Image compression using K-means clustering
Prerequisite: K-means clustering The internet is filled with huge amounts of data in the form of images. People upload millions of pictures every day on social media sites such as Instagram, and Facebook and cloud storage platforms such as google drive, etc. With such large amounts of data, image compression techniques become important to compress
6 min read
Image Segmentation using K Means Clustering
Image Segmentation: In computer vision, image segmentation is the process of partitioning an image into multiple segments. The goal of segmenting an image is to change the representation of an image into something that is more meaningful and easier to analyze. It is usually used for locating objects and creating boundaries. It is not a great idea t
4 min read
K means clustering using Weka
In this article, we are going to see how to use Weka explorer to do simple k-mean clustering. Here we will use sample data set which is based on iris data that is available in ARFF format. There are 150 iris instances in this dataset. Before starting let's have a small intro about clustering and simple-k. Note: This article assumes that the data ha
3 min read
Clustering Text Documents using K-Means in Scikit Learn
Clustering text documents is a typical issue in natural language processing (NLP). Based on their content, related documents are to be grouped. The k-means clustering technique is a well-liked solution to this issue. In this article, we'll demonstrate how to cluster text documents using k-means using Scikit Learn. K-means clustering algorithm The k
2 min read
K-Means clustering on the handwritten digits data using Scikit Learn in Python
K - means clustering is an unsupervised algorithm that is used in customer segmentation applications. In this algorithm, we try to form clusters within our datasets that are closely related to each other in a high-dimensional space. In this article, we will see how to use the k means algorithm to identify the clusters of the digits. Load the Datase
5 min read
K-Means Clustering using PySpark Python
In this tutorial series, we are going to cover K-Means Clustering using Pyspark. K-means is a clustering algorithm that groups data points into K distinct clusters based on their similarity. It is an unsupervised learning technique that is widely used in data mining, machine learning, and pattern recognition. The algorithm works by iteratively assi
4 min read
K-Means Clustering in R Programming
K Means Clustering in R Programming is an Unsupervised Non-linear algorithm that cluster data based on similarity or similar groups. It seeks to partition the observations into a pre-specified number of clusters. Segmentation of data takes place to assign each training example to a segment called a cluster. In the unsupervised algorithm, high relia
3 min read
ML | Mini Batch K-means clustering algorithm
Prerequisite: Optimal value of K in K-Means Clustering K-means is one of the most popular clustering algorithms, mainly because of its good time performance. With the increasing size of the datasets being analyzed, the computation time of K-means increases because of its constraint of needing the whole dataset in main memory. For this reason, sever
6 min read
Image Segmentation Using Fuzzy C-Means Clustering
This article delves into the process of image segmentation using Fuzzy C-Means (FCM) clustering, a powerful technique for partitioning images into meaningful regions. We'll explore the fundamentals of FCM, its advantages over traditional methods, and provide a step-by-step guide to implementing FCM for image segmentation using Python. By the end of
7 min read
Is K Means Clustering Considered Supervised or Unsupervised Machine Learning?
Answer: K-means clustering is considered an unsupervised machine learning algorithm. This categorization is because it does not rely on labeled input data for training; instead, it organizes data into clusters based on inherent similarities without any predefined labels.In this article we will explore K-Means Clustering in Machine Learning Unsuperv
2 min read
What is the Most Efficient K-Means Clustering Package in R?
K-means clustering is one of the most popular unsupervised machine learning algorithms used for grouping data points into a specified number of clusters. Each data point is assigned to the cluster with the nearest mean, serving as a prototype of the cluster. In R, several packages provide implementations of the K-means algorithm, each with differen
6 min read
K means Clustering - Introduction
K-Means Clustering is an Unsupervised Machine Learning algorithm, which groups the unlabeled dataset into different clusters. The article aims to explore the fundamentals and working of k mean clustering along with the implementation. Table of Content What is K-means Clustering?What is the objective of k-means clustering?How k-means clustering work
9 min read
How do k-means clustering methods differ from k-nearest neighbor methods
The fundamental distinction between K-Means clustering and K-Nearest Neighbors (KNN) lies in their core purposes and how they handle data. Specifically, K-Means is an unsupervised learning method used for clustering, whereas KNN is a supervised learning algorithm used for classification or regression. K-Means is an unsupervised learning method used
4 min read
DBSCAN Clustering in ML | Density based clustering
Clustering analysis or simply Clustering is basically an Unsupervised learning method that divides the data points into a number of specific batches or groups, such that the data points in the same groups have similar properties and data points in different groups have different properties in some sense. It comprises many different methods based on
7 min read
Difference between Hierarchical and Non Hierarchical Clustering
Hierarchical Clustering: Hierarchical clustering is basically an unsupervised clustering technique which involves creating clusters in a predefined order. The clusters are ordered in a top to bottom manner. In this type of clustering, similar clusters are grouped together and are arranged in a hierarchical manner. It can be further divided into two
2 min read
How to sample large database and implement K-means and Knn in R
Sample large database becomes essential to reduce the amount of data for better and faster prediction. The goal is to extract a representative subset of data from a larger dataset for analysis, as it might be impractical or time-consuming to analyze the entire dataset. Whereas R is an open-source programming language and software environment for da
13 min read
ML | Random Initialization Trap in K-Means
Random initialization trap is a problem that occurs in the K-means algorithm. In random initialization trap when the centroids of the clusters to be generated are explicitly defined by the User then inconsistency may be created and this may sometimes lead to generating wrong clusters in the dataset. So random initialization trap may sometimes preve
2 min read
Color Quantization using K-Means in Scikit Learn
In this article, we shall play around with pixel intensity value using Machine Learning Algorithms. The goal is to perform a Color Quantization example using KMeans in the Scikit Learn library. Color Quantization Color Quantization is a technique in which the color spaces in an image are reduced to the number of distinct colors. Even after the colo
2 min read
Demonstration of K-Means Assumptions
We explore scenarios that reveal the strengths and limitations of the algorithm in this Scikit-learn investigation of K-means assumptions. We study the sensitivity of K-means to incorrect cluster sizes, the difficulties it faces with anisotropic distributions, the difficulties it faces with different cluster variances, and the issue of unevenly siz
6 min read
ML | K-means++ Algorithm
Prerequisite: K-means Clustering – IntroductionDrawback of standard K-means algorithm:One disadvantage of the K-means algorithm is that it is sensitive to the initialization of the centroids or the mean points. So, if a centroid is initialized to be a "far-off" point, it might just end up with no points associated with it, and at the same time, mor
5 min read
Understanding Types of Means | Set 1
It is one of the most important concepts of statistics, a crucial subject to learning Machine Learning.   Arithmetic Mean: It is the mathematical expectation of a discrete set of numbers or averages. Denoted by X̂, pronounced as “x-bar”. It is the sum of all the discrete values in the set divided by the total number of values in the set. The formul
3 min read
KMeans Clustering and PCA on Wine Dataset
K-Means Clustering: K Means Clustering is an unsupervised learning algorithm that tries to cluster data based on their similarity. Unsupervised learning means that there is no outcome to be predicted, and the algorithm just tries to find patterns in the data. In k means clustering, we specify the number of clusters we want the data to be grouped in
6 min read
Agglomerative clustering with and without structure in Scikit Learn
Agglomerative clustering is a hierarchical clustering algorithm that is used to group similar data points into clusters. It is a bottom-up approach that starts by treating each data point as a single cluster and then merges the closest pair of clusters until all the data points are grouped into a single cluster or a pre-defined number of clusters.
10 min read
three90RightbarBannerImg