Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

K Means Clustering in R: Step by Step Tutorial with Example

Updated on 24 November, 2022

8.74K+ views
10 min read

As a data scientist, you’ll be doing a lot of clustering. There are many types of clustering algorithms available, and you should be well-versed in using all of them. In this article, we’ll discuss a popular clustering algorithm, K-means, and see how it’s used in R. 

You’ll find out the basic theory behind K-means clustering in R and how it’s used. We’ve also discussed a practical example later in the article. Be sure to bookmark this article for future reference. Read more about clustering analysis in Data Mining.

Before we begin discussing K means clustering in R, we should take a look at the types of clustering algorithms that are present so you can better understand how this algorithm deals with them. 

Read: Top R Libraries in Data Science

Types of Clustering

When you group several objects in such a way that the objects which are the most similar to each other are in a close cluster, it’s called clustering. The distance between the objects could be relevant to their similarity. Similarity shows the strength of the relationship between two distinct objects in data science. Clustering is a popular data mining technique. Clustering finds its applications in numerous industries and areas, including image analysis, machine learning, data compression, pattern recognition, and many others.

Clustering is of two types – Hard and Soft. Let’s discuss each of them briefly.

  • In a hard cluster, a data point would belong to a cluster totally, or it wouldn’t belong to it at all. There’s no in-between. 
  • In a soft cluster, a data object could be related to more than one cluster at once due to some likelihood or probability. 

Learn data science course online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Types of Clustering Algorithms

Like there are different types of clusters, there are different types of clustering algorithms too. You can differentiate algorithms based on their cluster model. This means you can distinguish them based on how they form clusters. If we’d start talking about all kinds of clustering algorithms, this guide will become too long and far from the main point. So, we’ll only discuss a few prominent types of clustering algorithms. There is connectivity- based, centroid based, density-based, and distribution based clustering algorithms. 

Basic Concept of K-Means

The basic concept of K-means is quite simple. K-means is related to defining the clusters so that the total within-cluster variation is as minimum as possible. There are a variety of k-means algorithms. The most common k-means algorithm is the Hartigan-Wong algorithm, which states that the total intra-cluster variation is equal to the sum of the squared distances Euclidean distances between centroids and their items:

W(Ck)=xiCk(xi–k)2

Here xi refers to a data point that belongs to the cluster Ck and k refers to the mean value of the data points present in the cluster Ck.

The value of xi should be such that the sum of the squared distance between xi and k is the minimum. 

What is the K-means Algorithm?

To use the algorithm, we’ll first have to state the number of clusters, K, that will be present in our result. The algorithm first selects K objects randomly to act as initial cluster centers. We call those objects cluster centroids or means. Then we assign the remaining objects to their closest centroids. The Euclidean distance between the cluster centroids and the objects determines how close they are.

After we have assigned the objects to their respective centroids, the algorithm calculates the mean value of the clusters. After this re-computation, we recheck the observations to see if they might be closer to a different cluster. Then, we reassign the objects to centroids accordingly. We keep repeating these steps until assigning clusters stops. This means we stop repeating the iterations when the clusters formed in an iteration are the same as the ones in their previous iteration. 

Our learners also read: Learn Python Online for Free

Using K-Means Clustering (Example)

Now that you know what is the K-means algorithm in R and how it works let’s discuss an example for better clarification. In this example, we’ll cluster the customers of an organization by using the database of wholesale customers. The data for this problem is available at the machine learning repository of Berkley UCI. You can check it out here.

First, we’ll read the data. And then get a summary of it. After reading the data and seeing its summary, you’ll see that there are some stark differences between the top consumers in different categories. You’ll find some outliers, which you can’t remove easily with normalization (or scaling). With this data, a business would want to see what their mid-range of customers buy most of the time. That’s because a company would have a decent idea of what their top customers buy. 

To create a cluster of the mid-level customers, we should first get rid of the top layer of customers from each category. So we’ll remove the top 5 ones and create a new set. Here’s how we’ll do so:

top.n.custs <- function (data,cols,n=5) { #Requires some data frame and the top N to remove

idx.to.remove <-integer(0) #Initialize a vector to hold customers being removed

for (c in cols){ # For every column in the data we passed to this function

col.order <-order(data[,c],decreasing=T) #Sort column “c” in descending order (bigger on top)

#Order returns the sorted index (e.g. row 15, 3, 7, 1, …) rather than the actual values sorted.

idx <-head(col.order, n) #Take the first n of the sorted column C to

idx.to.remove <-union(idx.to.remove,idx) #Combine and de-duplicate the row ids that need to be removed

}

return(idx.to.remove) #Return the indexes of customers to be removed

}

top.custs <-top.n.custs(data,cols=3:8,n=5)

length(top.custs) #How Many Customers are needed to be Removed?

data[top.custs,] #Examine the available customers

data.rm.top<-data[-c(top.custs),] #Remove the required Customers

 
With this new file, we can start working on our cluster analysis. To perform the cluster analysis, we’ll use the following code:

 
set.seed(76964057) #Set the seed for reproducibility

k <-kmeans(data.rm.top[,-c(1,2)], centers=5) #Create 5 clusters, Remove columns 1 and 2

k$centers #Display&nbsp;cluster centers

table(k$cluster) #Give the count of data points in each cluster

When you have run this code on the given database, you’ll get these results:

  • The first cluster would have high-quality detergents but the low quantity of fresh food products
  • The third cluster would have more fresh product

You’ll need to use withinss and betweenss for a detailed interpretation of the results. k$withinss is equal to the sum of the distance’s square between each data object from the center of the cluster. The lower the range, the better would be the result. If the withinss measure is high in your data, it means there are many outliers present, and you need to perform data cleaning. k$betweenss is the sum of the distance’s square between different centers of the clusters. The distance between the cluster centers should be as high as possible. 

Read: 6 More commonly used data structures in R

You should take help of trial and error to get the most accurate results. To do so, you’ll need to try out various values for K. When the graph of your results doesn’t show increment in the withinss of your clusters, that point would be the most suitable value for K. You can find the value of K through the following code:

rng<-2:20 #K from 2 to 20

tries <-100 #Run the K Means algorithm 100 times

avg.totw.ss <-integer(length(rng)) #Set up an empty vector to hold all of points

for(v in rng){ # For each value of the range variable

 v.totw.ss <-integer(tries) #Set up an empty vector to hold the 100 tries

 for(i in 1:tries){

 k.temp <-kmeans(data.rm.top,centers=v) #Run kmeans

 v.totw.ss[i] <-k.temp$tot.withinss#Store the total withinss

 }

 avg.totw.ss[v-1] <-mean(v.totw.ss) #Average the 100 total withinss

}

plot(rng,avg.totw.ss,type=”b”, main=”Total Within SS by Various K”,

 ylab=”Average Total Within Sum of Squares”,

 xlab=”Value of K”)

That’s it. Now you can use the graph you get from this code to get the best value for K and use it to get the required results. Use this example to try out your knowledge of K-means clustering in R. Here is all the code we’ve used in the example:

data <-read.csv(“Wholesale customers data.csv”,header=T)

summary(data)

top.n.custs <- function (data,cols,n=5) { #Requires some data frame and the top N to remove

idx.to.remove <-integer(0) #Initialize a vector to hold customers being removed

for (c in cols){ # For every column in the data we passed to this function

col.order <-order(data[,c],decreasing=T) #Sort column “c” in descending order (bigger on top)

#Order returns the sorted index (e.g. row 15, 3, 7, 1, …) rather than the actual values sorted.

idx <-head(col.order, n) #Take the first n of the sorted column C to

idx.to.remove <-union(idx.to.remove,idx) #Combine and de-duplicate the row ids that need to be removed

}

return(idx.to.remove) #Return the indexes of customers to be removed

}

top.custs <-top.n.custs(data,cols=3:8,n=5)

length(top.custs) #How Many Customers to be Removed?

data[top.custs,] #Examine the customers

data.rm.top <-data[-c(top.custs),] #Remove the Customers

set.seed(76964057) #Set the seed for reproducibility

k <-kmeans(data.rm.top[,-c(1,2)], centers=5) #Create 5 clusters, Remove columns 1 and 2

k$centers #Display cluster centers

table(k$cluster) #Give a count of data points in each cluster

rng<-2:20 #K from 2 to 20

tries<-100 #Run the K Means algorithm 100 times

avg.totw.ss<-integer(length(rng)) #Set up an empty vector to hold all of points

for(v in rng){ # For each value of the range variable

v.totw.ss<-integer(tries) #Set up an empty vector to hold the 100 tries

for(i in 1:tries){

k.temp<-kmeans(data.rm.top,centers=v) #Run kmeans

v.totw.ss[i]<-k.temp$tot.withinss#Store the total withinss

}

avg.totw.ss[v-1]<-mean(v.totw.ss) #Average the 100 total withinss

}

plot(rng,avg.totw.ss,type=”b”, main=”Total Within SS by Various K”,

ylab=”Average Total Within Sum of Squares”,

xlab=”Value of K”)

upGrad’s Exclusive Data Science Webinar for you –

Watch our Webinar on The Future of Consumer Data in an Open Data Economy

Conclusion

We hope you liked this guide. We’ve tried to keep it concise and comprehensive. If you have any questions about the K-means algorithm, feel free to ask us. We’d love to answer your queries. 

If you are curious to learn about data science, check out IIIT-B & upGrad’s Executive PG Program in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.

 

Frequently Asked Questions (FAQs)

1. What are some of the disadvantages of using K-means?

Outliers can pull centroids, or outliers may be given their own cluster rather than being disregarded. As K-means is stochastic, it cannot ensure that the global optimal clustering solution will be found. In reality, outliers and noisy data might make the algorithm highly sensitive. Before grouping, consider eliminating or cutting outliers. When grouping data with variable sizes and densities, K-means has difficulties. You must generalize K-means to cluster such data. Even if they clearly belong to the same cluster, the k-means algorithm does not allow data points that are far apart to share the same cluster.

2. What is the elbow method in K-means?

The k-means method relies heavily on finding the appropriate number of clusters. The Elbow Approach is a widely used method for determining the best K value. The elbow technique performs K-means clustering on the dataset for a range of K values on the graph, and then computes an average score for all clusters for each value of K. The distortion score, which is the sum of square distances from each point to its assigned center, is computed by default. Other data-driven models, such as the number of main components to characterize a data set, can utilize the same technique to determine the number of parameters.

3. How can we find outliers in K-means?

Outliers in K-Means clustering may be discovered using both a distance-based and a cluster-based technique. Outliers are discovered using dendrograms in the case of hierarchical clustering. The project's objective is to discover and eliminate outliers in order to make clustering more accurate. The data is partitioned into K groups by allocating them to the nearest cluster centers in the K-means based outlier identification approach. We may then calculate the distance or dissimilarity between each item and its cluster center, and choose the outliers with the greatest distances. Because extreme values may quickly impact a mean, the K-means clustering method is sensitive to outliers.