How to use elbow method to find the best no of clusters to use K Means?
Aug 25, 2019 2,361 views

## 1 answer to this question.

Elbow method allows the user to know the best fit number of clusters.

1. Compute clustering algorithm (e.g., k-means clustering) for different values of k. For instance, by varying k from 1 to 10 clusters.
2. For each k, calculate the tot.withinss.
3. Plot the curve of above values against the number of clusters from step 1.
4. The value at the bend of the plot is considered as the best fit value for no of clusters.
```totwss=sapply(1:10, function(k) { kmeans(mtcars\$mpg,k)\$tot.withinss})
k = data.frame(k = 1:6,totwss = totwss)
ggplot(k,aes(k,totwss))+geom_line()``` In this case, you can take 2 or 3 as per your choice.

answered Aug 26, 2019 by anonymous
• 33,030 points

## ​can we do the feature extraction using K means clustering? If yes how can we do that?

Hi@Pushpender, You can do that. But K-Means is ...READ MORE

+1 vote

Dear Learner, Hope you are doing well. Can you ...READ MORE

## Using "dplyr" to summarise multiple columns

You can use the "sumamrise_all()" function for ...READ MORE

The below is the code to perform ...READ MORE

## Use different distance formula other than euclidean distance in k means

K-means is based on variance minimization. The sum-of-variance formula ...READ MORE

+1 vote

## k means vs KNN

K-means clustering is basically an unsupervised clustering ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

+1 vote